YouTip LogoYouTip

Av Event Ended

HTML Audio/Video DOM ended Event | Simple Tutorials body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background-color: #f8f9fa; padding-top: 20px; } .container { max-width: 1000px; margin: 0 auto; background: #fff; padding: 30px; border-radius: 8px; box-shadow: 0 0 10px rgba(0,0,0,0.1); } h1 { color: #2c3e50; text-align: center; margin-bottom: 20px; font-size: 2rem; } .nav-link { font-size: 1rem; color: #3498db; margin-right: 15px; } .nav-link:hover { color: #2980b9; text-decoration: underline; } .sidebar { background-color: #f1f1f1; padding: 20px; border-radius: 8px; margin-bottom: 20px; font-size: 0.9rem; } .sidebar a { display: block; margin-bottom: 10px; color: #2c3e50; text-decoration: none; } .sidebar a:hover { color: #3498db; text-decoration: underline; } pre { background-color: #f4f4f4; border: 1px solid #ddd; padding: 15px; border-radius: 5px; overflow-x: auto; font-family: 'Courier New', monospace; font-size: 0.9rem; margin-top: 10px; } code { font-family: 'Courier New', monospace; font-size: 0.9rem; background-color: #f4f4f4; padding: 2px 6px; border-radius: 3px; color: #d3394c; } .note { background-color: #e8f4fc; border-left: 4px solid #3498db; padding: 15px; margin: 20px 0; border-radius: 4px; font-size: 0.95rem; } footer { text-align: center; margin-top: 40px; padding-top: 20px; border-top: 1px solid #eee; color: #7f8c8d; font-size: 0.85rem; }

HTML Audio/Video DOM ended Event

Home HTML JS CSS Bookmark Search

Simple Tutorials -- Learning not just technology, but also dreams!

HTML Audio/Video DOM ended Event

The ended event is fired when the media playback has finished (or stopped for other reasons).

This event is typically used to trigger actions after a video or audio file finishes playing, such as displaying a message or loading the next item.

Syntax

element.addEventListener("ended", function(event) {
  // Your code here
}, false);

Example

Below is an example demonstrating how to handle the ended event in HTML5 audio/video elements:

<!DOCTYPE html>
<html>
<head>
<title>Audio/Video Ended Event Example</title>
<script>
function handleEnded() {
  alert("The media has finished playing!");
}
</script>
</head>
<body>

<audio id="myAudio" controls>
  <source src="example.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

<script>
document.getElementById("myAudio").addEventListener("ended", handleEnded);
</script>

</body>
</html>

Browser Support

The ended event is supported by all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera.

Related Events

  • play – Fired when playback starts.
  • pause – Fired when playback is paused.
  • timeupdate – Fired periodically during playback.
  • loadedmetadata – Fired when metadata is loaded.

Summary

The ended event is essential for handling the end of media playback. It allows developers to execute custom logic after a video or audio file completes, enhancing user experience with interactive feedback.

© 2024 Simple Tutorials. All rights reserved.
← Av Event ErrorAv Event Abort β†’