Horje

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




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