JPLayer playlist get song title when changing

I am using jplayer autostart playlist. A playlist appears, songs are played, everything is in order. But I want to get the name of the current song when jplayer changes to the next song. I could not find the documentation for this.

How can I get the current name of the song when the song was changed?

Here is a sample jplayer playlist 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 }); 
+4
source share
1 answer

You are using the jPlayer playlist list from the docs:

The third parameter is an object for defining jPlayer parameters and jPlayerPlaylist parameters. This object is passed to jPlayer (...)

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

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

So, in your code, you can add the last parameter to override the play jPlayer event. There you can access the name of the song being played at this point:

 play: function(e) { console.log(e.jPlayer.status.media.title); } 
+5
source

All Articles