Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop Mediaelement.js video only 5 times

I would like to loop my Mediaelement.js video only 5 times. I've found the setting where you can set loop: true, which makes you video loop. But with this setting, it loops infinitely. I would like to stop the loop after 5 times.

$(this).mediaelementplayer({
    loop: true,
    alwaysShowControls: false,
    startVolume: 0,
    features: [],
});

Does the Mediaelement have some extra settings to limit this loops? Or should I do this by using custom Javascript?

like image 864
Michiel Avatar asked Nov 12 '22 23:11

Michiel


1 Answers

there is an event that fire when the video ends, you could use it to know how many time the vid played and stop it at five, this code is not tested, but should point you in the right direction

var player = $('videoContainer').mediaelementplayer();
var playCount = 0;

player.media.addEventListener('ended', function(e) {
    playCount++;
    if (playCount>=5){
        player.stop();
    } 
}, false);
like image 130
gorhgorh Avatar answered Nov 15 '22 00:11

gorhgorh