Megi
Megi

Reputation: 113

Add function if song/track ended?

I'm using jPlayer plugin i want to add event function if last song/track + playlist ended.

Upvotes: 0

Views: 167

Answers (1)

Vanojx1
Vanojx1

Reputation: 5584

As you can see in the docs that event is fired when the playlist ended.

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"
);

As i don't know if myplaylist.current is an object or and index you can check the playlist finish using your own counter

your code need to be something like this

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

Upvotes: 1

Related Questions