Guys how do I play an mp3 file and then another once the first has finished?
I have tried the following without success..
$('#file1)[0].play( function () {
$('#file2)[0].play();
});
Can you use callbacks when playing audio?
Guys how do I play an mp3 file and then another once the first has finished?
I have tried the following without success..
$('#file1)[0].play( function () {
$('#file2)[0].play();
});
Can you use callbacks when playing audio?
According to W3Schools, you can use the
onended
event to detect if the HTML5 audio has finished playing.In jQuery:
For a demonstration see: http://jsfiddle.net/9PCEf/2/
You can do the rest after audio playing finished.
You are not calling a jQuery method to begin with.
You could attach an event handler to the
"onended"
event:You need to listen to the
onended
event.I used @blasteralfred's code to create a function to play a indefinite series of sound files using jQuery:
The conditional test for an array allows me to backport this to my existing code that calls this function with just a string. Thanks!