JQuery jPlayer - How to stop all players before starting the game?

I need to stop all other instances of jPlayer before playing a new one when I press the play button.

Thanks for the help.

+3
source share
5 answers

solvable

just assigned the onclick function to the playback trigger and performs the following functions:


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

+5
source

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

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

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

+1

:

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

: Jplayer

Or, alternatively, you can put this in an onclick or click event handler

$('[id^="jquery_jplayer"]').jPlayer("pause");
+1
source
$('#jPlayer_ID').jPlayer("pauseOthers");
+1
source

Source: https://habr.com/ru/post/1743988/


All Articles