2012-09-17 54 views
2

我不是不能讓當前的歌曲信息一個js編碼所以也許這是不工作只是因爲我的無知: 作爲一個非常最近的文章中jplayer用戶發現裏面組,就可以得到當前歌曲的相關信息監聽jplayer表演事件,像這樣:Jplayer 2.2.0:使用JavaScript

$("#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>'; 
} 

我jplayer的JavaScript之後插入一個<script type="text/javascript"></script>這裏面的代碼。 然後在頁面的主體中,我製作了一個<div id="currentTrackInfo"></div>標籤。

事實是,這段代碼不適合我,div保持空白,因爲它是。 也許我的錯誤是,我必須以某種方式調用函數?

回答

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 
    }); 
} 
+0

如果我要坐的歌曲時長?我將如何使用相同的代碼?因爲現在我只有標題和網址。 – Ionut

4

這裏檢查此

jQuery("#jquery_jplayer_1").bind(jQuery.jPlayer.event.play, function (event) 
    { 

     var current   = myPlaylist.current, 
     playlist  = myPlaylist.playlist; 
     jQuery.each(playlist, function (index, obj){ 
      if (index == current){ 
        alert(obj.title); 

      } // if condition end 
     }); 
    }); 

+0

謝謝你救了我:D – mshahbazm

+0

如果我想要歌曲持續時間怎麼辦?我將如何使用相同的代碼?因爲現在我只有標題和網址。 – Ionut