onemptied
onemptied event
The onemptied
event is triggered when the resource of a media element is removed or becomes unavailable. This can happen if playback is stopped by the user or if the media source is reset.
Syntax
addEventListener("emptied", (event) => {});
onemptied = (event) => {};
Example
These examples demonstrate how to attach an event listener to the emptied
event of an HTMLMediaElement
. When the event is triggered, a message is displayed to indicate that the event has been handled.
- Using
addEventListener()
:
const video = document.querySelector("video");
video.addEventListener("emptied", (event) => {
console.log("Uh oh. The media is empty. Did you call load()?");
});
- Using the
onemptied
event listener property:
const video = document.querySelector("video");
video.onemptied = (event) => {
console.log("Uh oh. The media is empty. Did you call load()?");
};
See also
Conclusion
The onemptied
event is triggered when the resource of a media element is removed or becomes unavailable. It typically occurs when the media source is reset or playback is stopped. This event helps handle changes in media availability effectively.
ondurationchange
The ondurationchange event is triggered when the duration of a media file is updated. This typically happens when an audio or video is loaded, changing the duration from "NaN" to a valid value.
onended
The onended event is triggered when an audio or video reaches its end. It is commonly used to display messages like "thanks for listening" or trigger other actions once playback finishes.