MediaError.code - Web APIs 编辑
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
.
Syntax
var myError = mediaError.code;
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
Name | Value | Description |
---|---|---|
MEDIA_ERR_ABORTED | 1 | The fetching of the associated resource was aborted by the user's request. |
MEDIA_ERR_NETWORK | 2 | Some kind of network error occurred which prevented the media from being successfully fetched, despite having previously been available. |
MEDIA_ERR_DECODE | 3 | Despite having previously been determined to be usable, an error occurred while trying to decode the media resource, resulting in an error. |
MEDIA_ERR_SRC_NOT_SUPPORTED | 4 | The associated resource or media provider object (such as a MediaStream ) has been found to be unsuitable. |
Example
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
var obj = document.createElement('video');
obj.onerror = function() {console.log("Error with media: " + obj.error.code);}
obj.src="https://example.com/blahblah.mp4";
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'MediaError.code' in that specification. | Living Standard | Initial definition |
Browser compatibility
BCD tables only load in the browser
See also
- The interface defining it,
MediaError
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论