lundi 30 mars 2015

Toogle icon (play/pause), and stop when another button is clicked

Hope this post is not doubled, since i've search a lot for my same question and i surely found some but none of them really helped me.


I just need to 'mix' the scripts i found so i get what i need, let me explain better with my code:


Script for play a song and stop when another is clicked (but no pause if i click the same button)



var currentsound;
function play_pause(player) {
if(currentsound)
{
currentsound.pause();
}
var myAudio = document.getElementById(player);
myAudio.play();
currentsound = myAudio;
myAudio.currentTime = 0;
myAudio.play();
}


And this is another script i found here for toogle the icon :



var play = false;
function toggle() {
var image = document.getElementById('image')
var scan = document.getElementById('scan');
play = !play;
if (play) {
image.src = "pause.png";
scan.play();
}
else {
image.src = "play.png";
scan.pause();
}
}


So what i basically want is just "mix" both codes (i've already tried a lot of times but couldn't make it work, because of my lack of skills in javascript) so i can toogle and play the song at the same time (also the toogle work for 1 img only, when i used on more than one, only the first toggle). And for last, just to implement the pause part on my buttons, as how it is (my first script) it only stop when other button is clicked but do not pause when i click the same I'd really really appreciate any kind of comment/advice that lead me to get my code running as i want. Best regards


Aucun commentaire:

Enregistrer un commentaire