开发者

jQuery jPlayer - How to stop all players before playing a new one?

开发者 https://www.devze.com 2022-12-29 06:36 出处:网络
I need to stop all other instances of jPlayer before playing a new one when i click play. Th开发者_如何学Canks for you help.SOLVED

I need to stop all other instances of jPlayer before playing a new one when i click play.

Th开发者_如何学Canks for you help.


SOLVED

just assigned onclick function to the play trigger and the functions does:


function stopall(){
    $(".jplyrselectr").jPlayer("stop");
}


Give all of your players a class (I think default is class="jp-jplayer"), then include the following "play" event handler in your initialisation options:

$("#jplayer1").jPlayer({
    ready: function() {
        $(this).jPlayer("setMedia", {
            mp3: "mp3/track1.mp3"
        });
    },
    play: function() {
        $(".jp-jplayer").not(this).jPlayer("stop");
    },
    swfPath: "js",
    wmode: "window"
});


maybe $("#jpId1, #jpId2, #jpId3").stop();


You can use this method:

$.jPlayer.pause(); // Pause all instances of jPlayer on the page

Reference: Jplayer develpment guide

Or alternatively you can put this in the onclick or the click event function handler

$('[id^="jquery_jplayer"]').jPlayer("pause");


$('#jPlayer_ID').jPlayer("pauseOthers");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号