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

Simulating Live TV


Hi I want simulate live tv with my playlist https://content.jwplatform.com/feeds/euwH95QL.rss . I proved the demo https://developer.jwplayer.com/jw-player/demos/basic/live-tv/ but I failed. Can you help me?

3 Community Answers

Alex

JW Player Support Agent  
0 rated :

Hi there,

In order for this to work properly, I believe you would need more than one playlist item in your playlist. Can you try again with multiple items in your playlist and let me know whether or not that works?

Thanks.

r...

User  
0 rated :

I tried but nothing appear. Can you give me a practic working example of the code? Because I don't understand this line "// In order for this demo to work, duration must be included for each playlist item.".


This is what I tried (I only modified the playlist ID):



<script type="text/javascript">

var playerInstance = jwplayer("myElement");

// In order for this demo to work, duration must be included for each playlist item.

playerInstance.setup({
"playlist": "//content.jwplatform.com/feeds/euwH95QL.rss"
});

playerInstance.on('displayClick', function() {
playerInstance.pause();
});

playerInstance.on('ready', function() {
var seconds = new Date().getMinutes()*60 + new Date().getSeconds();
var playlist = playerInstance.getPlaylist();
var offset = 0;

for (var index=0; index < playlist.length; index++) {
var duration = Math.round(playlist[index]['duration']);
if(offset + duration > seconds) {
playerInstance.playlistItem(index);
playerInstance.seek(seconds-offset);
break;
} else {
offset += duration;
}
}
});

</script>

Alex

JW Player Support Agent  
1 rated :

Hi there,

I made a slight change to the code in which I wrap the seek method inside of a .once(‘play’) event so that the player waits until it starts playing the new playlist item before it seeks. That seems to make it work.

However, there is one bigger issue that you have with this current setup. In order for it to work properly, the combined duration of your videos would need to be 60 minutes or longer. Right now, the combined duration of your three videos is 1,018 seconds, which is equal to just under 17 minutes. This means that this current setup will only work if it is viewed within the first 17 minutes of an hour.

For example, if I comment out this line:

var seconds = new Date().getMinutes()*60 + new Date().getSeconds();

and replace it with:

var seconds = 1000;

The player, once loaded, will begin playback with 18 seconds remaining in the third playlist item.

Here is the code:

var playerInstance = jwplayer("myElement");

// In order for this demo to work, duration must be included for each playlist item.

playerInstance.setup({
  playlist: "//content.jwplatform.com/feeds/euwH95QL.rss",
  width: 640,
  height: 360
});

playerInstance.on('displayClick', function() {
  playerInstance.pause();
});

playerInstance.on('ready', function() {
  var seconds = new Date().getMinutes()*60 + new Date().getSeconds();
  var playlist = playerInstance.getPlaylist();
  var offset = 0;

  for (var index=0; index < playlist.length; index++) {
      var duration = Math.round(playlist[index]['duration']);
      if(offset + duration > seconds) {
          playerInstance.playlistItem(index);
          playerInstance.once("play", function() {
            var seekTime = seconds - offset;
            playerInstance.seek(seekTime);
          });
          break;
      } else {
          offset += duration;
      }
  }
});'

Thank you!

This question has received the maximum number of answers.