Jump to content

subsequent clicks


rubing

Recommended Posts

Hey all,  I love php, but am addled by this javascript.  maybe you all can help me with something simple.

I am streaming mp3s on my site by making a call to a javascript api called soundmanager2.  This works fine: 

 

<a href=\"javascript:soundManager.play('mySound0','/clips/RickCarterJessica.mp3')\"><img align='left' src='images/play_button.png' alt='play' /></a>

 

However, I would like to let my visitors stop this sound from playing when they click on the link again.

Link to comment
https://forums.phpfreaks.com/topic/107307-subsequent-clicks/
Share on other sites

The code you posted does not help. Does the soundmanager script have a method for stopping the sound? If so, I wold create an intermediary function that does the switching.

 

Here is an example based upon the premise that you can stop the sound via soundManager.stop(). However, that is complete conjecture.

 

Create the following function (and global variable):

var playing = false;

function playMusic(soundID, path) {
  if (playing) {
    soundManager.stop(soundID);
    playing = false;
  } else {
    soundManager.play(soundID, path);
    playing = true;
  }
}

 

 

Change the link above as follows:

<a href=\"javascript:playMusic('mySound0','/clips/RickCarterJessica.mp3')\"><

 

EDIT: Based upon a quick review of the soundmanager methods it appears there is a stop() method, but requires you to pass the id. Modified the code above

Link to comment
https://forums.phpfreaks.com/topic/107307-subsequent-clicks/#findComment-550334
Share on other sites

neat.  so, i guess i would just need the correct soundmanager function to detect whether it is playing?

 

No, in the method I proposed above the global variable "playing" would detemine if the clip was playing or not. When the page first loads the variable is set to 'false'. When you click the link it will first determine the current value of 'playing'. If it is false it will start the clip and change the value of the variable to 'true'. If the value is already 'true' it will stop the clip and change the value to 'false'.

 

If you are trying to control multiple clips on the same page you will need to have several control variables or use an array.

Link to comment
https://forums.phpfreaks.com/topic/107307-subsequent-clicks/#findComment-550456
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.