如何让Firefox在播放过程中无缝恢复临时网络错误?
考虑一下:我们正在播放剪辑,我们在当前位置之前有一些预先缓冲的数据。有一次,我们的浏览器决定下载下一个数据块。如果失败,例如"连接被拒绝",然后Firefox立即停止播放,触发"错误"并设置" MEDIA_ERR_NETWORK"错误代码。
但是,Chrome会在重试之间不断重复,直到它放弃并触发“#34;错误"”。如果网络在此之前恢复,则用户不会注意到出现了问题。我是如何看待这一点的:即使我为Firefox编写了一些恢复javascript,我也无法在恢复过程中摆脱明显的停顿。正确?
<html>
<head>
</head>
<body>
<audio id="theplayer" controls src="2gb.wav" type="audio/wav" style="width: 100%;">
</audio>
<br/>
<a href="javascript:void(0)" onclick="theplayer.src = '2gb.wav';">reload</a>
<body>
<script>
var theplayer = document.getElementById("theplayer");
var currentTime;
theplayer.addEventListener("timeupdate", function () {
currentTime = theplayer.currentTime;
}, false);
theplayer.addEventListener("error", function () {
console.log("error: " + theplayer.error.code + "; pos: " + currentTime);
setTimeout(function() {
if (!theplayer.playing) {
console.log("try recover");
theplayer.src = "2gb.wav";
theplayer.currentTime = currentTime;
theplayer.play();
}
}, 1000);
}, false);
theplayer.addEventListener("abort", function () {
console.log("abort");
}, false);
theplayer.addEventListener("stalled", function () {
console.log("stalled");
}, false);
theplayer.addEventListener("suspend", function () {
console.log("suspend");
}, false);
</script>
</html>