rubing Posted May 26, 2008 Share Posted May 26, 2008 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 26, 2008 Share Posted May 26, 2008 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 Quote Link to comment Share on other sites More sharing options...
rubing Posted May 26, 2008 Author Share Posted May 26, 2008 neat. so, i guess i would just need the correct soundmanager function to detect whether it is playing? Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 26, 2008 Share Posted May 26, 2008 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. Quote Link to comment Share on other sites More sharing options...
rubing Posted May 27, 2008 Author Share Posted May 27, 2008 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.