HTML Audio/Video DOM ratechange Event
HTML Audio/Video DOM Reference
Example
Change the video playback speed and display the changed speed:
// Get the element with id="myVideo"
var vid = document.getElementById("myVideo");
// Set the video playback speed to 0.3 (slow motion)
function setPlaySpeed() {
vid.playbackRate = 0.3;
}
// Add a ratechange event to the
vid.onratechange = function() {myFunction()};
function myFunction() {
alert("Video playback speed changed");
}
Try it »
Definition and Usage
The ratechange event is triggered when the playback speed of the audio/video changes (for example, when the user switches to slow or fast playback mode).
This event is called through the audio/video's playbackRate property, which is used to set or return the playback speed of the audio/video.
Browser support
The numbers in the table indicate the version number of the first browser to support the event.
| Events | |||||
|---|---|---|---|---|---|
| ratechange | Yes | 9.0 | Yes | Yes | Yes |
Syntax
In HTML:
<
audio|video
onratechange="
myScript
">Try it
In JavaScript:
audio|video
.onratechange=function(){
myScript
};
Try it
In JavaScript, use the addEventListener() method:
audio|video
.addEventListener("ratechange",
myScript
);
Try it
Note: Internet Explorer 8 and earlier IE versions do not support addEventListener() method.
Technical Details
| Supported HTML tags: | |
|---|---|
| Supported JavaScript objects: | Audio, Video |
HTML Audio/Video DOM Reference