HTML Media Events

The media events are triggered by media such as images, audio, videos, etc. The media events may be applied to all elements but as the name shows they are best suitable for media elements. Media events support was limited in HTML4. However, most of the media events used today are added after HTML5.

Let’s explore media events supported by HTML.

HTML Media Events

This section provides a detailed overview of the media events supported by the HTML.

onabort

This event appears when the loading of the media(audio/video) is aborted. This event supports <audio> and <video> tags.

Syntax

<element onabort="script">

oncanplay

The oncanplay occurs when the specific media is about to play/run. For instance, if the video file is buffering(not completely buffered) enough to run, then this media event will be triggered for that element. The HTML tags supported by these media events are, <audio> and <video>.

Syntax

<element oncanplay="script">

oncanplaythrough

This event happens when the specific media file is buffered completely. The oncanplaythrough event occurs after the oncanplay event.

Syntax

<element oncanplaythrough="script">

onemptied

As the name of the attribute shows, this event happens when the specific element contains an empty media element.

Syntax

<element onemptied="script">

onended

The event happens when some audio or video has ended. This event supports <audio> and <video> tags.

Syntax

<element onended="script">

ondurationchange

This event triggers when the duration of the specific audio/video file has been changed.

Syntax

<element ondurationchange="script">

onerror

This event happens when the loading of any external file is failed. The HTML elements supported by this event are, <img>, <input type=”img”>, <object>, <link>, and <script>.

Syntax

<element onerror="script">

onloadeddata

This event happens when the media of the next frame is not enough to continue the uninterrupted play. The onloadeddata event supports <audio>, and <video>.

Syntax

<element onloadeddata="script">

onloadedmetadata

This event happens when the metadata of a specific media is loaded. The metadata refers to the duration and dimensions of that media element.

Syntax

<element onloadedmetadata="script">

onloadstart

This event happens whenever a specific media file is being loaded.

Syntax

<element onloadstart="script">

onpause

This event occurs when the specific media is paused by any source (maybe a user or any program). The <audio> and <video> are the tags supported by this event.

Syntax

<element onpause="script">

onplay

This event occurs when the media file is ready to start.

Syntax

<element onplay="script">

onplaying

This event happens when the media has been started (by a user or a program).

Syntax

<element onplaying="script">

onprogress

This event happens when the browser is loading the media/audio file.

Syntax

<element onprogress="script">

onratechange

This event is triggered when the video is being played at a slower or faster rate than the original.

Syntax

<element onratechange="script">

onseeking

This event occurs when the user navigates to a new position in an audio/video file.

Syntax

<element onseeking="script">

onseeked

This event is triggered when the user has finished the seeking process.

Syntax

<element onseeked="script">

onstalled

The onstalled event happens when the browser is trying to fetch the media file but the file is not available.

Syntax

<element onstalled="script">

onsuspend

This event triggers when the media is available to fetch but either the browser does not want to load or the loading is paused due to some reason.

<element onsuspend="script">

ontimeupdate

The ontimeupdate event occurs when the playing position (playing the media file by navigating to a different time) of the media file is changed.

Syntax

<element ontimeupdate="script">

onvolumechange

As the name shows, the event is triggered when the volume of the media file has been changed.

Syntax

<element onvolumechange="script">

onwaiting

The onwaiting event is triggered when the video is interrupted to buffer the next frame.

Syntax

<element onwaiting="script">

From the above-provided information, you would have learned the application of various media events.

Conclusion

The HTML events occur whenever any kind of manipulation happens to the media elements on the page. The HTML 5 is quite rich regarding the media events, as the number of media events has been increased from the previous HTML version. This article enlists the HTML media events, their purpose, and the syntax supported by all. The HTML media events can be used to keep a focus on the change that occurs due to the media.



from https://ift.tt/gnq6afB

Post a Comment

0 Comments