jQuery,为什么倒带playbackRate不起作用? [英] jQuery, why the rewind playbackRate doesn't work?

查看:876
本文介绍了jQuery,为什么倒带playbackRate不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了快进的playbackRate工作正常。现在我尝试使用负数的倒带部分,但它不起作用。 w3school说使用负数倒回来。
http://www.w3schools.com/tags/av_prop_playbackrate.asp
任何人可以告诉我我做错了什么?

I got the fast forward playbackRate work fine. Now I try with the rewind part with negative number but it doesn't work. The w3school say to use negative number to rewind it. http://www.w3schools.com/tags/av_prop_playbackrate.asp Anyone can tell me what I did wrong?

这里我的javascript工作代码为快进,

Here my javascript worked code for fast forward,

$("#speed").click(function() { // button function for 3x fast speed forward
    video.playbackRate = 3.0;
});

然后这里没有成功倒带代码,

Then here not success rewind code,

$("#negative").click(function() { // button function for rewind
    video.playbackRate = -3.0;
});


推荐答案

示例小提琴

Sample Fiddle

看起来不像播放率完整的浏览器支持关于倒带的选择。你可以使用 setinterval 伪造它并减去视频的 currentTime

Doesn't look like there is complete browser support for the playback rate option as far as rewind is concerned. You can fake it by using setinterval and subtracting the currentTime of the video.

var video = document.getElementById('video');
var intervalRewind;
$(video).on('play',function(){
    video.playbackRate = 1.0;
    clearInterval(intervalRewind);
});
$(video).on('pause',function(){
    video.playbackRate = 1.0;
    clearInterval(intervalRewind);
});
$("#speed").click(function() { // button function for 3x fast speed forward
    video.playbackRate = 3.0;
});
$("#negative").click(function() { // button function for rewind
   intervalRewind = setInterval(function(){
       video.playbackRate = 1.0;
       if(video.currentTime == 0){
           clearInterval(intervalRewind);
           video.pause();
       }
       else{
           video.currentTime += -.1;
       }
            },30);
});

我还为播放和暂停按钮添加了一些额外的监听器以清除间隔。可能还希望在快速前进和后退按钮上进行一些切换功能。

I also added some extra listeners for the play and pause button to clear the interval. Might want to look into doing some toggling feature on the fast foward and rewind buttons as well.

这篇关于jQuery,为什么倒带playbackRate不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆