[whatwg] Some media element details

On Fri, 16 May 2008, Antti Koivisto 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.]
> 
> 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);

I don't think I've ever seen a video player that shows this indicator. 
Could you show me an example of a video player UI that does this?


> Knowing whether media is playing or not is needed for other common UI elements
> too, for example to activate/deactivate time display timer,

I don't think the visibility of the time display timer in a typical video 
UI is actually directly correlated to the playback state. Again, could you 
show an example of this?


> to do play/pause button etc.

The state of a play/pause button is definitely not correlated to the 
playback state. It's correlated to the "paused" boolean.


> 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's syntactical sugar for something which, in practice, I don't think 
anyone would actually use.

If you know of any examples of video players that actually would (if 
reimplemented in HTML) make use of this, though, that would be a different 
matter.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Wednesday, 11 June 2008 17:36:15 UTC