MediaElement.js:触发事件,如果某个特定音频文件已结束

时间:2014-04-16 16:23:16

标签: javascript jquery mediaelement.js

参考MediaElement.js。如果某个特定音频文件已经结束,如何触发事件(调用函数)?

var myAudioFiles = ['audioFile1.wav', 'audioFile2.wav', 'audioFile3.wav'];
var myPlayer = new MediaElementPlayer('#myPlayer');

myPlayer.setSrc(myAudioFiles[0]);
myPlayer.play();

伪代码:

if (hasEnded(myAudioFiles[0])) {
    doSomething();
}

1 个答案:

答案 0 :(得分:2)

请试一试。

$(function(){
    $('audio,video').mediaelementplayer({
        success: function(player, node) {
            player.addEventListener('ended', function(e){
                player.src = 'media/somefile.mp4';
                player.load();
                player.play();
            });
        }
    });
});

从这里复制:
   mediaelement.js - play another video at end of 1st video