我正在使用 jplayer 播放列表和自动播放。显示播放列表,正在播放歌曲,一切正常。但我想在 jplayer 更改为下一首歌曲时获取当前歌曲名称。我找不到任何相关文档。
歌曲更改后如何获取当前歌曲名称?
这里是 jplayer 播放列表示例代码。
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
});
最佳答案
您正在使用 playlist addon jPlayer 的,来自文档:
The third parameter is an object to define the jPlayer options and jPlayerPlaylist options. This object is passed to jPlayer (...)
和here您可以看到 jPlayer 的可用事件列表。对您的问题有用的是:
$.jPlayer.event.play * Occurs when the media is played.
因此,在您的代码中,您可以添加最后一个参数来覆盖 jPlayer 的 play
事件。您可以在那里访问当时正在播放的歌曲的标题:
play: function(e) {
console.log(e.jPlayer.status.media.title);
}
关于jquery - jPLayer Playlist 获取更改时的歌曲名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31951508/