Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 媒体错误网络是即时的,即使一些缓冲数据仍然存在_Javascript_Google Chrome_Firefox_Html5 Audio - Fatal编程技术网

Javascript 媒体错误网络是即时的,即使一些缓冲数据仍然存在

Javascript 媒体错误网络是即时的,即使一些缓冲数据仍然存在,javascript,google-chrome,firefox,html5-audio,Javascript,Google Chrome,Firefox,Html5 Audio,如何让Firefox无缝地从播放期间的临时网络错误中恢复 考虑一下:我们正在播放一个片段,在当前位置之前有一些预缓冲数据。有一次,我们的浏览器决定下载下一块数据。如果失败,例如“连接被拒绝”,那么Firefox会立即停止播放,触发“错误”并设置“媒体错误网络”错误代码 然而,Chrome在重试之间的延迟越来越大,直到它放弃并触发“错误”。如果在此之前恢复网络,用户不会注意到出现了问题 我是如何看待这一点的:即使我为Firefox编写了一些恢复javascript,我也无法摆脱恢复过程中明显的停顿

如何让Firefox无缝地从播放期间的临时网络错误中恢复

考虑一下:我们正在播放一个片段,在当前位置之前有一些预缓冲数据。有一次,我们的浏览器决定下载下一块数据。如果失败,例如“连接被拒绝”,那么Firefox会立即停止播放,触发“错误”并设置“媒体错误网络”错误代码

然而,Chrome在重试之间的延迟越来越大,直到它放弃并触发“错误”。如果在此之前恢复网络,用户不会注意到出现了问题

我是如何看待这一点的:即使我为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>

var theplayer=document.getElementById(“theplayer”);
无功电流时间;
theplayer.addEventListener(“时间更新”,函数(){
currentTime=theplayer.currentTime;
},假);
theplayer.addEventListener(“错误”,函数(){
console.log(“错误:+theplayer.error.code+”;位置:+currentTime);
setTimeout(函数(){
如果(!theplayer.playing){
log(“尝试恢复”);
theplayer.src=“2gb.wav”;
theplayer.currentTime=当前时间;
player.play();
}
}, 1000);
},假);
theplayer.addEventListener(“中止”,函数(){
控制台日志(“中止”);
},假);
theplayer.addEventListener(“stalled”,函数)(){
控制台日志(“暂停”);
},假);
theplayer.addEventListener(“挂起”,函数(){
控制台日志(“暂停”);
},假);