Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Player + sharing + related


Hi,
i'm trying to integrate JWplayer into my app.
My setup is Jwplayer 7.12.8 + enabled sharing + enabled related from external RSS file.

Player initiation is here:
https://pastebin.com/QxAer18R

Related endpoint returns:
https://pastebin.com/H8CZF6Vx

Scenario
There is a player on page. The share buton is enabled and i can share with "some-current-url" address. When playing is finished i can choose from two related videos. Then player starts playback and share button is still enabled. After I press it, the share link is still "some-current-url" instead of "somelink8544" or "somelink8511" which i expected.

Any help?

12 Community Answers

Alex

JW Player Support Agent  
0 rated :

Where is some-current-url coming from? Is it a variable defined somewhere else on your page?

m...

User  
0 rated :

Hi Alex, thanks for your response.

At this moment i'm going to create simple example, to check all features that i need.

For now, it's just a hardcoded string. I guess it should be string with current url address but to simplify i set hardcoded string 'some-current-url' as sharing link.

Alex

JW Player Support Agent  
0 rated :

Forgive me but I am a little confused – if you set the sharing link to a string, “some-current-url”, then that is what the option will be set to. If you set it to a URL, then the sharing link would be the URL.

m...

User  
0 rated :

Yeah, that's absolutely correct.

What is strange for me - I can not set share url for each of related video (or I don't know how to do it).

Currently I setup player for video and set share url as 'some-current-url'. I need to set different share link for each of related video. How can I achive that?

Alex

JW Player Support Agent  
0 rated :

Can you give me an example URL of one of your related playlists?

m...

User  
0 rated :

Hi,

sure, https://pastebin.com/H8CZF6Vx (from my 1st post)

m...

User  
0 rated :

To be precise -

My jwplayer setup:

player.setup({
...
"related": {
"file": "/related/id,MEDIAID.html"
}
});

URL "/related/id,MEDIAID.html" is an endpoint in my application that returns related playlist for given MEDIAID file. You can check sample output here -
https://pastebin.com/H8CZF6Vx .

Thank you for your patience :)

Alex

JW Player Support Agent  
0 rated :

Can you try removing <jwplayer:sharing link> from the playlist and instead include the URL that should be shared in the <link> element?

m...

User  
0 rated :

Like this, right?

https://pastebin.com/jEFWfuL5

Sadly nothing changed.

I have started debuging sharing.js plugin. I have got access to minified file only but I think i have found function that return share link for every video.

function i(C, e) {
var n = C.indexOf("MEDIAID");
return n > 0 && e ? C.replace("MEDIAID", e) : n === -1 ? C : void 0
}
function a(C) {
var e = window.location.toString();
if (window.top !== window && (e = document.referrer),
n.link) {
var t = i(n.link, C);
e = t ? t : e
}
return e
}

Variable C is id of media, n is sharing-plugin options, in my case:

{
"link": "some-current-url"
}

In my opinion, there is only one method to set share url for related video - using MEDIAID token.

Alex

JW Player Support Agent  
-1 rated :

Hi there,

It looks like the permalink set in the dashboard will only be used in the sharing overlay if you embed the player with a single-line embed code generated by the dashboard. I did come up with a workaround that seems to work:

playerInstance.on("playlistItem", function(e) {
  var playerElement = playerInstance.getContainer();
  var linkIcon = playerElement.querySelector(".jw-sharing-icon-link");
  var link = linkIcon.parentNode.querySelector(".jw-sharing-textarea");
  link.removeAttribute("readonly");
  setTimeout(function() {
    link.textContent = playerInstance.getPlaylistItem().link;
  }, 1000);
});

The above is assuming var playerInstance = jwplayer('whateverYourPlayerElementsIdIs");

Can you try that out and see if it works?

m...

User  
0 rated :

First of all - your solution works :) Thanks for that.

I personally do not like solutions that use setTimeout function - there are not elegant but I understand that it's just a workaround and it's only way to achieve my goal.

I have made some changes in your code. This is how it looks right now:

player.on("playlistItem", function (e) {

var playerElement = player.getContainer();
var linkIcon = playerElement.querySelector(".jw-sharing-icon-link");
var link = linkIcon.parentNode.querySelector(".jw-sharing-textarea");
link.removeAttribute("readonly");
setTimeout(function () {

if (typeof e.link !== 'undefined') {
link.textContent = e.link;
}
}, 1000);
});


This solution resolve only problem of copy link option in share plugin. Other options like facebook, twitter still use default url addres. To override it, I have changed my jwplayer setup like this:

"sharing": {
...
sites: [
{
label: "facebook",
icon: 'facebook.png',
src: function (defaultUrl) {
var siteUrl = "http://www.facebook.com/sharer/sharer.php?u=[URL]";
return openShareWindow(defaultUrl, siteUrl);
}
},
{
label: "twitter",
icon: 'twitter.png',
src: function (defaultUrl) {
var siteUrl = "http://twitter.com/intent/tweet?url=[URL]";
return openShareWindow(defaultUrl, siteUrl);
}
},

Definition of openShareWindow function:

function openShareWindow(baseUrl, siteUrl) {
var videoLink = (typeof player.getPlaylistItem().link !== 'undefined') ? player.getPlaylistItem().link : baseUrl;

var redirectUrl = siteUrl.replace(/\[URL\]/gi, videoLink );

window.open(redirectUrl, "_blank");
window.focus()
}


Finally it works the way I need :)
Thanks for help Alex, I really appreciate it :)

Alex

JW Player Support Agent  
-1 rated :

Not a problem! I’m glad we got everything working for you.

This question has received the maximum number of answers.