歌曲/曲目结束后添加功能?

时间:2015-09-21 11:48:44

标签: javascript

我正在使用jPlayer插件我想在最后一首歌曲/曲目+播放列表结束时添加事件功能。

1 个答案:

答案 0 :(得分:1)

正如您在docs中看到的那样,当播放列表结束时会触发该事件。

var playlength = myplaylist.playlist.length
var currentSong = 0;


$("#jpId").jPlayer( {
  ready: function() { // The $.jPlayer.event.ready event
    $(this).jPlayer("setMedia", { // Set the media
      m4v: "m4v/presentation.m4v"
    }).jPlayer("play"); // Attempt to auto play the media
  },
  ended: function() { // The $.jPlayer.event.ended event
    currentSong++;
    if(currentSong==playlength)
          ------> Show your html
  },
  supplied: "m4v"
);

由于我不知道myplaylist.current是对象还是索引,您可以使用自己的计数器检查播放列表结尾

你的代码必须是这样的

var currentSong = 0;
$("#music").bind($.jPlayer.event.ended,function(event){
       currentSong++;
       if(myplaylist.playlist.length == currentSong) {
              $('.show').html('Ended');
        }
});