HTML onratechange Event Attribute

Description

The event attribute onratechange occurs when the audio / video playback speed changes (for example, when the user switches to slow or fast playback).

Syntax

<element onratechange="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE HTML>
<html>
<body>

<audio id="myAudio" controls onratechange="myFunction()">  
  <source src="audio.mp3" type="audio/mpeg">
  Your browser does not support the audio tag.
</audio>
<p id="demo">Change the playback speed of the audio file:</p>
<input type="range" min="0.5" max="3" step="0.1" value="1" oninput="changeRate(this)">

<script>
function myFunction() {
    document.getElementById("demo").innerHTML = "Audio speed: " + document.getElementById("myAudio").playbackRate;
}
function changeRate(obj) {
    document.getElementById("myAudio").playbackRate = obj.value;
}
</script> 

<p>This example shows how to use the onratechange attribute for an AUDIO element.</p>

</body>
</html>

Supported Tags

<audio> and <video>

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
XXYes3.5XX
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
YesYes4XXX