I am using Chrome and this is my code:
$('.sound').live('click', function () {
var sound = $("#letter_audio")[0];
sound.pause();
sound.currentTime = 0;
sound.play();
return false;
});
How come the sound plays the first time I click on play. then when I click again, it pauses, like the code goes. but the it justs stays on pause? i want it to play, then when i click on it again, go back to 0 and play again as in the code?
解决方案
I've had similar problems replaying audio, but managed to solve it by calling the load() method before the play() call. Try this:
$('.sound').live('click', function () {
var sound = $("#letter_audio")[0];
sound.load();
sound.play();
return false;
});
I think this is better than resetting the src attribute for two reasons:
Keeps the src value in the page content, rather than in the JavaScript
Works when you embed multiple elements of different audio formats: