Horje
HTML ontimeupdate Attribute

Definition and Usage

The ontimeupdate attribute defines a script to run when the playing position of an audio/video has changed.

This event is invoked by:

  • Playing the audio/video
  • Moving the playback position (like when the user fast forwards to a different point in the audio/video)

Tip: This timeupdate event is often used together with the currentTime property of the Audio/Video Object, which returns the current position of the audio/video playback, in seconds.


Applies to

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

Elements Event
<audio> timeupdate
<video> timeupdate

Browser Support

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


How to Run "myFunction" when the position of the audio changes - HTML ontimeupdate Attribute

Audio Example. This example demonstrates how to use the "ontimeupdate" attribute on an AUDIO element.
index.html
Example: HTML
<!DOCTYPE html> 
<html> 
<body> 

<p id="demo">Move to a new position in the audio:</p>

<audio id="myAudio" controls ontimeupdate="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>

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "You moved to position " + document.getElementById("myAudio").currentTime;
}
</script> 

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

</body> 
</html>

Output should be:

How to Run "myFunction" when the position of the audio changes - HTML ontimeupdate Attribute

How to Run "myFunction" when the position of the video changes - HTML ontimeupdate Attribute

Video Example. This example demonstrates how to use the "ontimeupdate" attribute on a VIDEO element. Move to a new position in the video.
index.html
Example: HTML
<!DOCTYPE html> 
<html> 
<body>

<p id="demo">Move to a new position in the video:</p>

<video id="myVideo" width="320" height="176" controls ontimeupdate="myFunction()">
  <source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/mp4">
  <source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_2mb.mp4" type="video/ogg">
  Your browser does not support HTML5 video.
</video>

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "You moved to position " + document.getElementById("myVideo").currentTime;
}
</script> 

<p>This example demonstrates how to use the "ontimeupdate" 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 position of the video changes - HTML ontimeupdate Attribute




html ontimeupdate attribute

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


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