What I need
I need a script (Javascript, jQuery, etc.) to rewind a video after clicking. We used a script that we found in some forums, but it is rewound in video with acceleration, which causes an action of your search to become full / strange. It would have to be at the same speed.
What I have
//[Rewind]
var video = document.getElementById('video');
var intervalRewind;
jQuery(video).on('play',function(){
video.playbackRate = 1.0;
clearInterval(intervalRewind);
});
jQuery(video).on('pause',function(){
video.playbackRate = 1.0;
clearInterval(intervalRewind);
});
jQuery("#btnVoltar").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 had better results by calculating values for the interval and the time subtraction based on the frames-per-second. The interval for one frame is calculated in milliseconds (1000 / fps) and the time subtraction for one frame is calculated in seconds (1 / fps).
I also set the
playbackRate
to zero when playing in reverse, since the playhead position is set manually.Also see:
Playing HTML5 Video Backwards @ nicbell.net.
Alternatively, you might consider controlling the frames-per-second by using
requestAnimationFrame
. See Controlling fps with requestAnimationFrame?Per your request, here is a version that accommodates multiple videos on a page by using classes instead of IDs. I also used the
requestAnimationFrame
method by markE described here: Controlling fps with requestAnimationFrame.