Using Plyr.io as soon as the video ends - restart the player

I use the plyr plugin to play videos on my site.

I try to restart the player (vimeo) when the video ends, but I was not very lucky. I am even trying to hide a log message, and this does not even work. Can anyone see where I'm wrong?

JSfiddle is attached here.

if ($('.main-hero__youtube__video').length) {
    console.log("Video player init");
    // Define the controls
    var plyr_options = {
        autoplay: true,
        clickToPlay: true,
        showPosterOnEnd: true,
        controls: ['mute','progress','play']
    };

    // Create the plyr instances - this defines players[0] as our primary player.
    var players =  plyr.setup(plyr_options);

    players[0].on('ended', function(event) {
      console.log("test");
    });

}
+4
source share
1 answer

You were close, you just had to call the method restart()(or play(), if you are looking for an infinite loop) in your player instance:

players[0].on('ended', function(event) {
    players[0].restart();
    // players[0].play(); // infinite loop
});

https://jsfiddle.net/yunxyfbh/

0

Source: https://habr.com/ru/post/1671341/


All Articles