Execute a JavaScript when the playing speed of the video is changed:
In this example, we assign an "onratechange" event to a video element.
The playbackRate property is used to change the playing speed of the video.
<!DOCTYPE html> <html> <body> <video id="myVideo" width="100" height="100" autoplay //from www .j a v a 2s .c o m controls onratechange="myFunction()"> <source src="video.mp4" type="video/mp4"> <source src="video.ogg" type="video/ogg"> Your browser does not support the video tag. </video><br> <p id="demo"></p> <button onclick="setPlaySpeed()" type="button"> Set video to be play in slow motion</button> <script> var x = document.getElementById("myVideo"); // Set the current playback speed of the video to 0.3 (slow motion) function setPlaySpeed() { x.playbackRate = 0.3; } // Alert some text when the playing speed of the video is changed function myFunction() { document.getElementById("demo").innerHTML = "The playing speed of the video was changed"; } </script> </body> </html>
The onratechange event occurs when the playing speed of the audio/video is changed.
This event is invoked by the playbackRate property of the Audio/Video Object.
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | Event |
Supported HTML tags: | <audio> and <video> |