Horje
HTML onratechange Attribute

Definition and Usage

The onratechange attribute defines a script to be run when the playing speed of the audio/video is changed (like when a user switches to a slow motion or fast forward mode).


Applies to

The onratechange attribute is part of the Event Attributes, and can be used on the following elements:

Elements Event
<audio> ratechange
<video> ratechange

Browser Support

The onratechange attribute has the following browser support for each element:


How to Run "myFunction" when the audio changes the rate - HTML onratechange Attribute

Audio Example. The audio's speed. This example demonstrates how to use the "onratechange" attribute on an AUDIO element.
index.html
Example: HTML
<!DOCTYPE html> 
<html> 
<body> 

<audio id="myAudio" controls onratechange="myFunction()">
  <source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/ogg">
  <source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>
<p id="demo">Change the speed of the audio</p>
<input type="range" min="0.5" max="3" step="0.1" value="1"oninput="changeRate(this)">

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "The audio's speed is " + document.getElementById("myAudio").playbackRate;
}

function changeRate(obj) {
  document.getElementById("myAudio").playbackRate = obj.value;
}
</script> 

<p>This example demonstrates how to use the "onratechange" attribute on an AUDIO element.</p>

</body> 
</html>

Output should be:

How to Run "myFunction" when the audio changes the rate - HTML onratechange Attribute

How to Run "myFunction" when the video changes the rate - HTML onratechange Attribute

Video Example. The video's speed. This example demonstrates how to use the "onratechange" attribute on a VIDEO element.
index.html
Example: HTML
<!DOCTYPE html> 
<html> 
<body> 

<video id="myVideo" width="320" height="176" controls onratechange="myFunction()">
  <source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/mp4">
  <source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/ogg">
  Your browser does not support HTML5 video.
</video>
<p id="demo">Change the speed of the video</p>
<input type="range" min="0.1" max="3" step="0.1" value="1"oninput="changeRate(this)">

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "The video's speed is " + document.getElementById("myVideo").playbackRate;
}

function changeRate(obj) {
  document.getElementById("myVideo").playbackRate = obj.value;
}
</script> 

<p>This example demonstrates how to use the "onratechange" attribute on a VIDEO element.</p>

<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>

</body> 
</html>

Output should be:

How to Run "myFunction" when the video changes the rate - HTML onratechange Attribute




html onratechange attribute

Type:
Develop
Category:
Web Tutorial
Sub Category:
HTML Attribute
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference