StudentIT
StudentIT

Reputation: 481

Why video defaultPlaybackRate doesn't work in Chrome?

I saw some examples of defaultPlaybackRate and they say it work on Chrome. So I use their example codes and run on Chrome, it doesn't change the speed to 3.0x when I click the button. Anyone can tell me why?

Here my javascript code,

$(document).ready(function(){

    var video = document.getElementById('video');

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

});

The HTML codes,

<button id="speed" type="button">3.0x</button>

and

<video id="video" width="930" height="500" controls>
        <source src="caption.mp4" type="video/mp4">
        <source src="caption.ogg" type="video/ogg" >
        <source src="caption.webm" type="video/webm" >
</video> 

Upvotes: 2

Views: 1885

Answers (1)

j08691
j08691

Reputation: 207923

Because once you change the defaultPlaybackRate you have to load the video again using video.load(); (or set it before the video has loaded). If you want to change the rate while the video plays, use playbackRate instead.

 var video = document.getElementById('video');
 $("#speed").click(function () { // button function for 3x fast speed
     video.defaultPlaybackRate = 3.0;
     video.load();
 });

or

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

jsFiddle example

Upvotes: 5

Related Questions