[whatwg] Some media element details
Antti Koivisto
antti at apple.com
Fri May 16 18:42:29 PDT 2008
On 14.5.2008, at 23:37, Ian Hickson wrote:
>> It would be nice to have a read-only attribute (called "playing" for
>> example) that would be true when the element is "actively playing".
>> Knowing if the playback is progressing is necessary for implementing
>> basic playback UIs with JS. It is clumsy and not very obvious that
>> you
>> need to do "var playing = !video.paused && !video.ended &&
>> video.readyState >= HTMLMediaElement.CAN_PLAY" to get this
>> information.
>
> What's the use case?
For example a simple playing state indicator:
function updatePlayState() {
var playIndicator = document.getElementById("playIndicator");
var playing = !video.paused && !video.ended && video.readyState >=
HTMLMediaElement.CAN_PLAY;
playIndicator.className = playing ? "playing" : "stopped";
}
video.addEventListener("play", updatePlayState);
video.addEventListener("pause", updatePlayState);
video.addEventListener("ended", updatePlayState);
video.addEventListener("waiting", updatePlayState);
Knowing whether media is playing or not is needed for other common UI
elements too, for example to activate/deactivate time display timer,
to do play/pause button etc. A direct way to get this information
(along with an associated event) would be good for API usability I
think:
function updatePlayState() {
var playIndicator = document.getElementById("playIndicator");
playIndicator.className = video.activelyPlaying ? "playing" :
"stopped";
}
video.addEventListener("playstatechanged", updatePlayState);
Of course it is sort of syntactical sugar...
>>
>> It might also be good to explicitly state that exceptions are
>> ignored.
>
> Which exceptions?
Yeah, after the change to check for EMPTY networkState there are no
longer any exceptions to could occur with the current algorithm.
antti
More information about the whatwg
mailing list