2

I'm working with jPlayer directly since the mp3-jplayer plugin for WordPress broke with the WP 3.5 update, and it seems to be abandoned by the developer.

One of the nice features of the plugin is that it displays the title of the current track in a div above the control bar. Also, if there's only a single song in the playlist, there's a script to hide the playlist, so you only have the track title above the control bar. I'm trying to add this functionality to the regular (non-plugin) jPlayer.

I can display the title in a new div with this code, from the jPlayer forum:

$("#jquery_jplayer_1").bind($.jPlayer.event.play, function (event) {
    var current = myPlaylist.current,
        playlist = myPlaylist.playlist;
    $.each(playlist, function (index, obj) {
        if (index == current) {
            $('.jp_current_track_title').text(obj.title);   
        }
    });
});

However, this does not load the track title when the page loads - it only displays after you press 'play.' Note that when the player loads, the first track in the playlist is highlighted (selected).

So my question is: how can I get the track title to load when the page loads?

Test page is here.

I'm new to javascript/jQuery.

Thanks in advance.

4

2 回答 2

0

换行:

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

 $("#jquery_jplayer_1").bind($.jPlayer.event.ready, function (event) {

以便在播放器准备好后更新 div。

于 2015-04-15T11:41:39.957 回答
0

Jplayer 还提供了一个就绪事件:$.jPlayer.event.ready. 一旦播放器加载,应该可以使用它来做同样的事情。

于 2013-09-09T19:55:52.000 回答