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
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
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
Share on other sites

slick! 

 

i really don't want to learn javascript but that's pretty cool.

 

Yes, I was planning on playing multiple clips on the page... I don't want to worry about that yet.  I still have a lot of the basics to figure out here.  Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.