5

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

Thanks for you help.

Mr_Nizzle
  • 6,644
  • 12
  • 55
  • 85

5 Answers5

7

SOLVED

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


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

Mr_Nizzle
  • 6,644
  • 12
  • 55
  • 85
4

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"
});
jackocnr
  • 17,068
  • 10
  • 54
  • 63
1
$('#jPlayer_ID').jPlayer("pauseOthers");
Taryn
  • 242,637
  • 56
  • 362
  • 405
Eric Hodonsky
  • 5,617
  • 4
  • 26
  • 36
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Roman C Mar 05 '13 at 18:57
  • 1
    Actually it does EXACTLY what the OP asked, you just have to extrapolate... if you can't use what I've given, you need to take a step back. I'm assuming he knows how to watch for the 'click play' event he's talking about. – Eric Hodonsky Mar 05 '13 at 19:00
  • 1
    This worked for me. Additionally, if you want to choose where to put the play head postion in seconds pass a second integer parameter. This is straight from the documentation: `// Equivalent to "stop others", passing time as zero. $("#jpId").jPlayer({ play: function() { $(this).jPlayer("pauseOthers", 0); // stop all players except this one. } });` – racl101 Sep 25 '14 at 06:24
1

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

makeitmorehuman
  • 11,287
  • 3
  • 52
  • 76
1

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");
Robin Rizvi
  • 5,113
  • 4
  • 27
  • 35
  • 1
    This does what you're asking, but then you have to fire the play event manually. Try just adding this to your jPlayer Obj: `$().jPlayer({play:function(){$(this).jPlayer("pauseOthers");}});` – Eric Hodonsky Mar 05 '13 at 19:01