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

查看:40
本文介绍了jQuery,为什么倒带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天全站免登陆