files/en-us/web/api/mediaerror/code/index.md
{{APIRef("HTML DOM")}}
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 {{domxref("MediaError.message")}}.
A numeric value indicating the general type of error which occurred. The possible values are described below, in Media error code constants.
This example creates a {{HTMLElement("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
const obj = document.createElement("video");
obj.onerror = () => {
console.error(`Error with media: ${obj.error.code}`);
};
obj.src = "https://example.com/blahblah.mp4";
{{Specifications}}
{{Compat}}
MediaError.code property