MediaError: code property - Web APIs | MDN

MediaError: code property

Baseline
Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

>

The read-only property MediaError.code returns a numeric value which represents the kind of error that occurred on a media element. To get a text string with specific diagnostic information, see MediaError.message.

Value

A numeric value indicating the general type of error which occurred. The possible values are described below, in Media error code constants.

Media error code constants

Examples

This example creates a <video> element, establishes an error handler for it, and then sets the element's src attribute to the video resource to present in the element. The error handler outputs a message

js
const obj = document.createElement("video");
obj.onerror = () => {
  console.error(`Error with media: ${obj.error.code}`);
};
obj.src = "https://example.com/blahblah.mp4";

Specifications

Specification
HTML>
# dom-mediaerror-code-dev>

Browser compatibility

See also

  • MediaError: Interface used to define the MediaError.code property