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>
How to Run "myFunction" when the audio changes the rate - HTML onratechange Attribute | HTML Attribute |
How to Run "myFunction" when the video changes the rate - HTML onratechange Attribute | HTML Attribute |
Type: | Html |
Category: | Web Tutorial |
Sub Category: | HTML Attribute |
Uploaded by: | Admin |