Javascript DOM onratechange Event via HTML Tag onratechange function

Introduction

In JavaScript:

object.onratechange = function(){
       myScript};

In this example, we use the HTML DOM to assign an "onratechange" event to a video element.

The playbackRate property is used to change the playing speed of the video.

View in separate window

<!DOCTYPE html>
<html>
<body>
<video id="myVideo" 
       width="100" 
       height="100" autoplay controls>
  <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>
// Get the video element with id="myVideo"
var x = document.getElementById("myVideo");

// Set the current playback speed of the video to 0.3 (slow motion)
function setPlaySpeed() {//www  .j  a v  a2s  .c  om
  x.playbackRate = 0.3;
}

x.onratechange = function() {myFunction()};

function myFunction() {
  document.getElementById("demo").innerHTML = "The playing speed of the video was changed";
}
</script>

</body>
</html>
Bubbles: No
Cancelable: No
Event type: Event
Supported HTML tags: <audio> and <video>



PreviousNext

Related