MediaError: message property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2021.
The read-only property MediaError.message
returns a human-readable string offering specific diagnostic details related to the error described by the MediaError
object, or an empty string (""
) if no diagnostic information can be determined or provided.
Value
A string providing a detailed, specific explanation of what went wrong and possibly how it might be fixed. This is not a generic description of the MediaError.code
property's value, but instead goes deeper into the specifics of this particular error and its circumstances.
If no specific details are available, this string is empty.
Examples
Logging MediaError messages
This example creates an <audio>
element, establishes an error handler for it, then lets the user click buttons to choose whether to assign a valid audio file or a missing file to the element's src
attribute.
The error handler outputs log lines to a box onscreen describing the error, including the code
, the message
, and a hint that may be more useful for visitors than the diagnostic message
:
The example creates an <audio>
element and lets the user assign either a valid music file to it, or a link to a file which doesn't exist.
This lets us see the behavior of the error
event handler, which is received by an event handler we add to the <audio>
element itself.
First, it gets the MediaError
object describing the error from the error
property on the HTMLAudioElement
representing the audio player.
The error's numeric code
is checked against MediaError
constants, which are initially undefined.
If the err.code
is equal to any constant, it creates a generic hint with MediaError.message
added to the log line to provide more detailed diagnostic information for developers.
The resulting text is added to the <pre>
element:
Click the "Valid file" button to start playback as expected, the "Missing file" button to try to load a missing resource, and the "Wrong format" button to try to set an SVG file as the source for the audio element.
Comparing the log output for the two error cases illustrates the difference between a MediaError
's code
and message
:
Specifications
Specification |
---|
HTML # dom-mediaerror-message-dev |
Browser compatibility
See also
MediaError
: Interface used to define theMediaError.message
property<audio>
,<video>