简体   繁体   English

HTML5 playbackRate和Firefox

[英]HTML5 playbackRate and Firefox

I have a page with a HTML5 video player. 我有一个带有HTML5视频播放器的页面。 I created a very simple playback speed toggle button using jQuery. 我使用jQuery创建了一个非常简单的播放速度切换按钮。

The user clicks the button, and it multiplies the speed of the video's playbackRate property by 2 with each press. 用户单击该按钮,每按一次,它将视频的playbackRate属性的速度乘以2。

So you can go from 1x to 2x, 4x, 8x, 16x, 32x, 64x, 128x... and so on. 所以你可以从1x到2x,4x,8x,16x,32x,64x,128x ......等等。

However, in Firefox, the video's playbackRate on my page never goes beyond 5x. 但是,在Firefox中,我页面上的视频播放速率永远不会超过5倍。

As soon as the playbackRate is 4, and the script multiplies it by 2 - it turns into 5 (instead of 8). 一旦playbackRate为4,并且脚本将其乘以2 - 它变为5(而不是8)。

This issue does not happen while testing the same page in Google Chrome. 在Google Chrome中测试同一页面时,不会发生此问题。

Here is my script: 这是我的脚本:

$('#change_speed').click(function()
{
  var current_speed = ($('#video').get(0).playbackRate).toFixed(0);

  console.log('playback speed: ' + $('#video').get(0).playbackRate); //For debugging

  if(current_speed == 0)
  {
     $('#video').get(0).playbackRate = 1;
  }
  else
  {
    $('#video').get(0).playbackRate = $('#video').get(0).playbackRate * 2;
  }

});

There is no more code in my function. 我的函数中没有更多代码。 There is no other handler or script interfering. 没有其他处理程序或脚本干扰。 I click the button, I break before the multiplier: playbackRate is 4. I break after the multiplier and the playbackRate is 5. 我点击按钮,我在乘数之前断开:playbackRate是4.我在乘数后断开,playbackRate是5。

If it's 1, the multiplier returns 2. If it's 2, the multiplier returns 4. If it's 4, the multiplier returns 5. ...What!? 如果它是1,则乘数返回2.如果它是2,则乘数返回4.如果它是4,则乘数返回5. ...什么!?

In Chrome, the speed keeps doubling like intended. 在Chrome中,速度与预期一致。 Why is it capping at 5 in Firefox? 为什么它在Firefox中的上限为5? Am I missing something? 我错过了什么吗?

From the MDN 来自MDN

Most browsers stop playing audio outside playbackRate bounds of 0.5 and 4, leaving the video playing silently. 大多数浏览器停止在10.5和4的playbackRate界限之外播放音频,使视频静默播放。 It's therefore recommended for most applications that you limit the range to between 0.5 and 4. 因此,建议大多数应用程序将范围限制在0.5到4之间。

Edit: Each browser handles moving outside of this recommended range differently. 编辑:每个浏览器处理此推荐范围之外的处理方式不同 Firefox happens to clamp the value range from 0.5 to 5. Chrome clamps from 0.5 to 16. If you go outside the recommended range, you will get different behavior across all browsers so I suggest clamping it in your code to 4x. Firefox恰好将值范围设置为0.5到5. Chrome会从0.5到16之间进行限制。如果超出推荐范围,您将在所有浏览器中获得不同的行为,因此我建议将其在代码中加以4倍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM