2012-05-06 26 views
1

在我的頁面中有一些mp3鏈接,我使用jplayer。點擊單獨鏈接時如何更新jplayer函數播放?jplayer在單個頁面中的多個mp3鏈接

$(document).ready(function() { 

$("#jquery_jplayer_1").jPlayer({ 

    ready: function(event) { 
     $(this).jPlayer("setMedia", { 
      mp3: "test_1.mp3", //my mp3 file 

     }); 
    }, 
    swfPath: "http://www.jplayer.org/2.1.0/js", 
    supplied: "mp3" 
    }); 
});  

我的MP3鏈接:

<a href="javascript:listen(1);" class="jp-play" ></a> 
<a href="javascript:listen(2);" class=" jp-play" ></a> 
<a href="javascript:listen(3);" class=" jp-play" ></a> 
<a href="javascript:listen(4);" class=" jp-play" ></a> 
<a href="javascript:listen(5);" class=" jp-play" ></a> 

回答

0

HTML:

<a href="test_1.mp3" class="jp-play"></a> 
<a href="test_2.mp3" class="jp-play"></a> 

JS:

$(document).ready(function() { 
    readMP3("test_1.mp3");// play one mp3 if document is loaded 

    $(".jp-play").click(function(event){ 
     event.preventDefault(); 
     readMP3($(this).attr("href")); 
    }) 

}); 

function readMP3(_src){ 
$("#jquery_jplayer_1").jPlayer({ 
    ready: function(event) { 
     $(this).jPlayer("setMedia", { 
      mp3: _src, 
     }); 
    }, 
    swfPath: "http://www.jplayer.org/2.1.0/js", 
    supplied: "mp3" 
    }); 
} 
+0

它不工作的第二個鏈接,當它點擊它test_1.mp3播放 – user1264362

+0

,因爲你沒有一個名爲'test_2.mp3'的MP3 – mgraph

+0

在這個鏈接每次test1.mp3播放。我不明白爲什麼。 http://www.dilyurdu.com/audio.htm – user1077300

1

嘿,你可以做到以下幾點。

我實例在頁面加載的球員:

jQuery("#jquery_jplayer_1").jPlayer({ 
swfPath: "http://www.jplayer.org/latest/js/Jplayer.swf", 
supplied: "mp3", 
wmode: "window", 
preload:"auto", 
autoPlay: true, 
errorAlerts:false, 
warningAlerts:false 
}); 

然後偵聽器,這將是唯一爲每個項目裏面,你需要:A)取曲目名稱/ URL,我想你應該能夠弄清楚這一點。

B)打發軌道的setMedia

jQuery("#jquery_jplayer_1").jPlayer("setMedia", { 
mp3: "http:xxxx.rackcdn.com/"+track+".MP3" 
}); 

C)播放音軌

jQuery("#jquery_jplayer_1").jPlayer("play"); 

爲了讓您需要在您的可玩的項目安裝監聽器的軌道ID(也許AA可玩類?)並從那一個獲得曲目。