Developer Guide Javascript API Reference Developer Tools Release Notes

Simulating Live TV

A demo that simulates live TV. The playlist item and position are determined by system date/time.

github
// In order for this demo to work, duration must be included for each playlist item.
const playerInstance = jwplayer('player').setup({
  'playlist': 'https://cdn.jwplayer.com/feeds/DrqpQIzP.rss'
});

playerInstance.on('displayClick', playerInstance.pause);

playerInstance.on('ready', function() {
  const thisDate = new Date();
  const seconds = (thisDate.getMinutes() * 60) + thisDate.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;
    }
  }
});
This player implementation is a Proof of Concept only provided to show the possibilities of the JW Player and Platform and should not be taken as an offer to create, edit or maintain custom integration or development.