How to repeat video with TVJS Player ?

I want to repeat playing video with TVJS Player. But I can't find like a 'repeat' property on player object.

First I tried to set seekTime to zero when playbackState change to 'end' state. But It dosen't work.


player.addEventListener("stateWillChange", function(e) {
  if (player.playbackState == 'end') {
    player.seekToTime(0);
    player.play();
  }
});

Next, Push same MediaItem object many time. It works find, but not elegant.


var mediaItem = new MediaItem("video", videoURL);
player.playlist.push(mediaItem);
player.playlist.push(mediaItem);
player.playlist.push(mediaItem);
....
(100 times?)
....


Finally, Set time based trigger to push MediaItem. It works find. But I have to know video lenght before playing.


player.addEventListener("timeDidChange", function(e) {
if (e.time >= VIDEO_LENGTH) {
  player.playlist.push(mediaItem);
}, { interval: 1});


Please tell me the best way to implement to repeat video.

Accepted Reply

You could start with 2 media item objects (both referring to the same video) and listen for mediaItemWillChange event on the player. In the event handler you could remove the first item form the playlist and append it at the end.

Replies

You could start with 2 media item objects (both referring to the same video) and listen for mediaItemWillChange event on the player. In the event handler you could remove the first item form the playlist and append it at the end.