javascript 'AbortError: 操作被中止。' - 在 Firefox 中调整 HTML 5 video.currentTime 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53039068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 10:05:21  来源:igfitidea点击:

'AbortError: The operation was aborted.' - Error when adjusting HTML 5 video.currentTime in Firefox

javascriptfirefoxhtml5-video

提问by Jesse Reza Khorasanee

When using Firefox and changing the position of a video using HTML5 video. Does anyone have insight to what causes this?

使用 Firefox 并使用 HTML5 视频更改视频的位置时。有没有人了解导致这种情况的原因?

Here are my ideas:

以下是我的想法:

  1. Setting it to a time value that has no corresponding frame - I have attempted to always set it to a time where a frame exists to counter this
  2. The video frame does not load by the time the next frame is asked for - in order to test this I have set the timeout to 5 ms, this definitely drops the amount of errors so that is some evidence that this is the source of the error.
  1. 将其设置为没有相应帧的时间值 - 我试图始终将其设置为存在帧的时间以解决此问题
  2. 视频帧在请求下一帧时未加载 - 为了测试这一点,我将超时设置为 5 毫秒,这肯定会降低错误数量,因此有证据表明这是错误的来源.

I have made slider that adjusts video time that replicates the error:

我制作了滑块来调整复制错误的视频时间:

var vid = $('#v0')[0];
var slider = document.getElementById('vidSlider')
linkVideoToSlider();

vid.onplay = vid.onclick = function() {
  vid.onplay = vid.onclick = null;

  setTimeout(function() {
    vid.pause();
    slider.value = vid.currentTime / vid.duration * 100
    vid.currentTime += (1 / 29.97);

  }, 12000);

  setInterval(function() {
    $('#time').html((vid.currentTime * 29.97).toPrecision(5));
    slider.value = vid.currentTime / vid.duration * slider.max;
  }, 100);
};

function linkVideoToSlider() {
  var adjustVideoTime = function() {
    //Note that we attempt to adjust to a time that has a frame.
    setTimeout(function() {
      vid.currentTime = Number.parseFloat(slider.value / 29.97).toFixed(4);
    }, 5);
  }
  slider.oninput = adjustVideoTime
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
Frame number:
<p id="time"></p>
<video id="v0" controls tabindex="0" autobuffer preload>
    <source type="video/webm; codecs=&quot;vp8, vorbis&quot;" src="http://www.html5rocks.com/tutorials/video/basics/Chrome_ImF.webm"></source>
    <source type="video/ogg; codecs=&quot;theora, vorbis&quot;" src="http://www.html5rocks.com/tutorials/video/basics/Chrome_ImF.ogv"></source>
    <source type="video/mp4; codecs=&quot;avc1.42E01E, mp4a.40.2&quot;" src="http://www.html5rocks.com/tutorials/video/basics/Chrome_ImF.mp4"></source>
    <p>Sorry, your browser does not support the &lt;video&gt; element.</p>
</video>
<div class="slidecontainer">
  <p>Time of video slider:</p>
  <input type="range" min="0" max="1024" value="0" class="slider" id="vidSlider">
</div>

if you prefer JSFiddle: https://jsfiddle.net/tehsurfer/9ahz5rmd/52/

如果你更喜欢 JSFiddle:https://jsfiddle.net/tehsurfer/9ahz5rmd/52/

采纳答案by Jesse Reza Khorasanee

This is a reported bugin Firefox.

这是Firefox 中报告的错误

AbortError: The operation was aborted

AbortError: The operation was aborted

Is output to console when either:

在以下任一情况下输出到控制台:

  1. A seek in video element is aborted.
  2. The time of a video element is adjusted.
  1. 视频元素中的查找被中止。
  2. 调整视频元素的时间。

Some developers there say that Firefox performs much slower than Chrome or Edge in these scenarios, but I haven't found a way to validate a difference personally.

那里的一些开发人员说 Firefox 在这些情况下的执行速度比 Chrome 或 Edge 慢得多,但我还没有找到一种方法来验证个人差异。

I will update this answer if a bug fix or workaround is found.

如果找到错误修复或解决方法,我将更新此答案。

Update:

更新:

After updating Firefox to 60.5.1esr it appears to be fixed and performance seems to have improved. However if you are running Firefox Developer edition, the bug still remains even after updating.

将 Firefox 更新到 60.5.1esr 后,它似乎已修复,性能似乎有所提高。但是,如果您运行的是 Firefox Developer 版本,即使更新后该错误仍然存​​在。