W3C home > Mailing lists > Public > whatwg@whatwg.org > May 2008

[whatwg] Some media element details

From: Antti Koivisto <antti@apple.com>
Date: Fri, 16 May 2008 18:42:29 -0700
Message-ID: <FA54794E-BA4F-491B-A817-2DEF9F44E05D@apple.com>
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 >=  
	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  

function updatePlayState() {
	var playIndicator = document.getElementById("playIndicator");
	playIndicator.className = video.activelyPlaying ? "playing" :  
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.

Received on Friday, 16 May 2008 18:42:29 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:02 UTC