In JavaScript, I have code like this:
var sound = new Audio(name);
sound.onended = function () {
alert("finished");
}
sound.play();
That is, after the sound.play
method has finished, I w开发者_StackOverflow中文版ant to alert that it is finished. This works in IE9, but is there a way to do it in Chrome?
I have also tried a callback like the code below, but it doesn't work:
sound.play(function () {alert("finished")});
Since you're using jQuery, consider using something like jPlayer. It will make your events much easier and consistent across browsers. It uses HTML5 audio on browsers that support it and Flash on browsers that don't support HTML5 audio. You can also use the SoundManager2.
If you manually use HTML5 audio then remember that Firefox and Opera don't support MP3. They support Ogg Vorbis. Safari and IE don't support Ogg Vorbis but support MP3. Chrome supports both MP3 and Ogg Vorbis but doesn't support WAV. Do you try to play WAV by any chance? If you do then it won't work on Chrome.
精彩评论