Ask questions and get good answers on jQuery

This should be simple, but I can't find a way to send a "stop" command to the player. Can anyone help?

asked Jan 20 at 16:42

lronick's gravatar image

lronick
1


Sorry, forgot to mention - I'm using miniAudioPlayer.

answered Jan 20 at 16:47

lronick's gravatar image

lronick
1

Hi, just click again on the play btn :-)

answered Jan 20 at 17:53

Matteo%20Bicocchi's gravatar image

Matteo Bicocchi ♦♦
1776129

Yeah, that's the way a human would stop it. I want to stop it from a JavaScript so I can control playback from another element on the page.

answered Jan 20 at 17:55

lronick's gravatar image

lronick
1

I got it working, not sure if it's the "best" way.

I modified the jquery.mb.miniPlayer.js script to include a public method that will return an object reference to the player with a specific ID. To do this, I added the private function "getPlayer" after the changeFile function, as follows (don't forget to add a comma after the closing "}" in the changeFile function):

getPlayer:function() { var ID= $(this).attr("id"); var $player=$("#"+"MP_"+ID); return $player; }

Then I added the public method "mb_getPlayer" to the end of the file, as follows:

$.fn.mb_getPlayer = $.mbMiniPlayer.getPlayer;

Now I can get a reference to any player object in my own JavaScript code by calling:

var myPlayer = $('#m1').mb_getPlayer(); //m1 is the ID of my player

Finally, I can use the "myPlayer" object to call any of the generic "jPlayer" methods, including "pause", as follows:

myPlayer.jPlayer("pause");

If anyone has a better idea, let me know.

answered Jan 21 at 14:30

lronick's gravatar image

lronick
1

In the latest gitHub release there are some new public method that let you control the player via javascript:

  $.fn.mb_miniPlayer_play();
  $.fn.mb_miniPlayer_stop();
  $.fn.mb_miniPlayer_destroy();
  $.fn.mb_miniPlayer_getPlayer();

You can use them as follow:

  $('#myPlayer').mb_miniPlayer_stop()

Bye, Matteo

answered Jan 26 at 15:50

Matteo%20Bicocchi's gravatar image

Matteo Bicocchi ♦♦
1776129

edited Jan 26 at 15:51

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×3
×1

Asked: Jan 20 at 16:42

Seen: 80 times

Last updated: Jan 26 at 15:51

jQuery main site - Matteo Bicocchi