HTML5 Guidelines for Web Developers

(coco) #1
4.7 Video and Scripting—A Simple Video Player 97

The attribute readyState describes which state a media element is currently in. It
has the possible values listed in Table 4.6.


Table 4.6 Constants of the “readyState” attribute


Value Constant Description

0 HAVE_NOTHING No data is available on the current playback
position.
1 HAVE_METADATA Metadata, such as length and dimension, are pres-
ent, but no data can be played yet.

2 HAVE_CURRENT_DATA Data for the current position is available but is not
really enough to begin playback.
3 HAVE_FUTURE_DATA Sufficient data for current and future playback po-
sitions is available to start playback.

4 HAVE_ENOUGH_DATA The browser is sure that it can keep playing the
media stream without interruption if the network
state remains the same.

If anything should really go wrong during loading or playback, an error event is
fired, narrowing down the relevant error in its code attribute:


video.addEventListener("error", function(e) {
alert(e.code);
}, false);


This callback function therefore returns one of the possible values shown in Ta-
ble 4.7 in e.code.


Table 4.7 Constants in the “code” attribute of the “MediaError” interface


Value Constant Description

1 MEDIA_ERR_ABORTED Loading was aborted by the user.
2 MEDIA_ERR_NETWORK A network error has occurred.

3 MEDIA_ERR_DECODE An error occurred while decoding the
media stream.
4 MEDIA_ERR_SRC_NOT_SUPPORTED The media format is not supported.
Free download pdf