具体来说,如果其中一个音频请求失败和缓冲停止,是否有一种方法来检测该状态?
是的,几乎没有办法做到这一点!但是,如果要捕获错误类型,可以将错误事件侦听器附加到源:
$('audio').addEventListener('error', function failed(e) {
// audio playback failed - show a message saying why
// to get the source of the audio element use $(this).src
switch (e.target.error.code) {
case e.target.error.MEDIA_ERR_ABORTED:
alert('You aborted the video playback.');
break;
case e.target.error.MEDIA_ERR_NETWORK:
alert('A network error caused the audio download to fail.');
break;
case e.target.error.MEDIA_ERR_DECODE:
alert('The audio playback was aborted due to a corruption problem or because the video used features your browser did not support.');
break;
case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED:
alert('The video audio not be loaded, either because the server or network failed or because the format is not supported.');
break;
default:
alert('An unknown error occurred.');
break;
}
}, true);
你能指出另一个来源吗?
在错误处理函数内部,您可以使用音频元素的src属性更改源:
var audio = $(this);
audio.src = "new-audio-file.mp3";
audio.load();
另一种选择是使用以下语法将多个源添加到同一个音频标签中:
//In case that you can't load the ogv file it will try to load test.mp3
关于管理多个音频文件
如果您正在考虑管理206个音频文件,我建议使用一个插件.我一直在使用SoundManager2一段时间,这是非常好的!