2

我不是 js 编码员,所以这可能只是因为我的无知而无法正常工作:正如在 jplayer 用户组中的一篇最近的帖子中发现的那样,您可以通过这种方式获取当前歌曲信息以收听 jplayer 播放事件:

    $("#jquery_jplayer_1").bind($.jPlayer.event.play, function(event) { 
    updateCurrentTrackInfo(myPlaylist.playlist[myPlaylist.current]);   // send out the media info object for the current track in the playlist
});

// custom function to update the external current track div
function updateCurrentTrackInfo(obj) {
            document.getElementById('currentTrackInfo').innerHTML = '<em>Now Playing&#8230;</em><span>'+obj.title+'</span> by <span>'+obj.artist+'</span>';
}

<script type="text/javascript"></script>我在 jplayer javascript 之后插入了这段代码。然后在页面的正文中我做了一个<div id="currentTrackInfo"></div>标签。

事实是这段代码对我不起作用,div 保持空白。也许我的错误是我必须以某种方式调用该函数?

4

2 回答 2

4

在这里检查这个

jQuery("#jquery_jplayer_1").bind(jQuery.jPlayer.event.play, 函数(事件)
    {   

        var current = myPlaylist.current,
        播放列表 = myPlaylist.playlist;
        jQuery.each(播放列表,函数(索引,obj){
            如果(索引 == 当前){
                    警报(obj.title);

            } // 如果条件结束
        });
    });

于 2013-02-28T11:14:07.387 回答
0

请检查一下

function add_song(){
    var current = myPlaylist.current,
        playlist = myPlaylist.playlist;
    jQuery.each(playlist, function (index, obj) {
       if (index == current) {
          alert(obj.title);
        } // if condition end
    });
 }
于 2012-10-01T08:10:57.360 回答