javascript - Playbutton animation -
i have 1 code starts playing audio when click on image. need edit it. make when click on image should start playing audio, change image another. know how it?
code:
<!doctype html> <html> <head> <script type="text/javascript"> function playsound(el,soundfile) { if (el.mp3) { if(el.mp3.paused) el.mp3.play(); else el.mp3.pause(); } else { el.mp3 = new audio(soundfile); el.mp3.play(); } } </script> </head> <body> <span id="dummy" onclick="playsound(this, 'http://listen.shoutcast.com/newfm128mp3');"> <img src="https://static.wixstatic.com/media/e2aefa_1969d5f605404431bb558b4ff9e60966~mv2.png/v1/crop/x_10,y_33,w_52,h_51/fill/w_52,h_51,al_c/e2aefa_1969d5f605404431bb558b4ff9e60966~mv2.png" name="bottom-1" width="50" height="45" border="0" id="bottom-1"/> </span> </body> </html>
try this:
<!doctype html> <html> <head> <script type="text/javascript"> //create new function update image source on click. function updateimage(el, soundfile) { //determine if music playing or paused adjust image source accordingly. if(soundfile.mp3.paused) { el.src = "pausedimagesrc"; } else { el.src = "playimagesrc"; } }; function playsound(el,soundfile) { if (el.mp3) { if(el.mp3.paused) el.mp3.play(); else el.mp3.pause(); } else { el.mp3 = new audio(soundfile); el.mp3.play(); } //call new function made whenever sound toggled. updateimage(document.getelementbyid("bottom-1"), el); }; </script> </head> <body> <span id="dummy" onclick="playsound(this, 'http://listen.shoutcast.com/newfm128mp3');"> <img src="https://static.wixstatic.com/media/e2aefa_1969d5f605404431bb558b4ff9e60966~mv2.png/v1/crop/x_10,y_33,w_52,h_51/fill/w_52,h_51,al_c/e2aefa_1969d5f605404431bb558b4ff9e60966~mv2.png" name="bottom-1" width="50" height="45" border="0" id="bottom-1"/> </span> </body> </html>
all did add new function called updateimage
changes image src based upon if audio paused or not.
jsfiddle: https://jsfiddle.net/b0wgh4em/1/
Comments
Post a Comment