Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jPLayer Playlist get song name on change

I'm using jplayer playlist with autoplay. Playlist is shown, songs are playing,it is ok. But I want to get current songs name when jplayer changes to next song. I couldnt find any documentation for this.

How can I get the current song name when song is changed?

Here is jplayer playlist sample code.

var myPlaylist = new jPlayerPlaylist({
  jPlayer: "#jquery_jplayer_N",
  cssSelectorAncestor: "#jp_container_N"
}, [
  {
    title:"Song 1",
    artist:"Artist 1",
    mp3:"http://www.example.com/audio/song1.mp3",
    oga:"http://www.example.com/audio/song1.ogg"
  },
  {
    title:"Song 2",
    artist:"Artist 2",
    mp3:"http://www.example.com/audio/song2.mp3",
    oga:"http://www.example.com/audio/song2.ogg"
  }
], {
  playlistOptions: {
    autoPlay: true,
    enableRemoveControls: true
  },
  swfPath: "/js",
  supplied: "ogv, m4v, oga, mp3",
  smoothPlayBar: true,
  keyEnabled: true,
  audioFullScreen: false // Allows the audio poster to go full screen via keyboard
});
like image 720
bencagri Avatar asked Aug 11 '15 20:08

bencagri


1 Answers

You are using the playlist addon of jPlayer, from the docs:

The third parameter is an object to define the jPlayer options and jPlayerPlaylist options. This object is passed to jPlayer (...)

And here you can see the list of available events of jPlayer. The one useful for your question is:

$.jPlayer.event.play * Occurs when the media is played.

So, in your code, you could add a last parameter to override the play event of jPlayer. There you can access the title of the song being played at that moment:

play: function(e) {
    console.log(e.jPlayer.status.media.title);
}
like image 176
zed Avatar answered Oct 01 '22 15:10

zed