English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag大全

HTML Audio/Video DOM error attribute

The error attribute is the latest MediaError object; if there is no error, it is null. When the project receives the error event, it can determine the details of what happened when checking this object.

 HTML Audio/Video DOM Reference Manual

Online Example

Get the video error status:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML Audio/video error attribute usage-Basic Tutorial(oldtoolbag.com)</<title>
</<head>
<body>
<button onclick="getError()" type="button">Get the video error status</button>
<br> 
<video id="video"1" controls="controls" autoplay="autoplay">
  <source src="movie_no_exist.mp"4" type="video"/mp4">
  <source src="movie_no_exist.ogg" type="video"/ogg">
  Your browser does not support HTML5 video tag.
</video>
<script>
myVid=document.getElementById("video"1);
function getError()
{ 
  alert(myVid.error.code);
} 
</script> 
</body>
</html>
Test to see ‹/›

Definition and Usage

The error attribute returns the MediaError object.
The MediaError object has a code property that contains the audio/Video error status.

Browser Compatibility

IEFirefoxOperaChromeSafari

Only Internet Explorer 9 Supports the error attribute.

Syntax

audio|video.error.code

Return value

TypeDescription
NumberThe code property of the MediaError object returns a numeric value that represents the audio/Video error status:
  • 1 = MEDIA_ERR_ABORTED - The retrieval process is aborted by the user

  • 2 = MEDIA_ERR_NETWORK - Error occurs during download

  • 3 = MEDIA_ERR_DECODE - Error occurs during decoding

  • 4 = MEDIA_ERR_SRC_NOT_SUPPORTED - Audio not supported/Video

 HTML Audio/Video DOM Reference Manual