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

[whatwg] Video Element Events? - Use Case: Custom Progress Bar

From: Eric Carlson <eric.carlson@apple.com>
Date: Fri, 31 Oct 2008 12:17:58 -0700
Message-ID: <4CE269FC-BE9A-4F93-802D-EDFDC63364BF@apple.com>
Ian -

On Oct 28, 2008, at 10:36 PM, Chris Double wrote:

> On Wed, Oct 29, 2008 at 5:22 PM, Charles Iliya Krempeaux
> <supercanadian at gmail.com> wrote:
>>
>> Perhaps I didn't read the spec carefully enough, but I don't see  
>> any such
>> event.
>
> You're looking for the 'timeupdate' event. This gets raised whenever
> the current playback position changes. From the spec section 4.8.10.8:
>
> "If the time was reached through the usual monotonic increase of the  
> current
> playback position during normal playback, the user agent must then  
> queue a task
> to fire a simple event called timeupdate at the element. (In the  
> other cases,
> such as explicit seeks, relevant events get fired as part of the  
> overall
> process of changing the current playback position.)"
>
> Although this is hidden away in the cue ranges section, it happens on
> normal playback without cue ranges.
>
   I think requiring a user agent to post events as a movie plays is a  
mistake. It will mean that *every* page will incur the overhead, even  
if no scripts are listening for the events.

   I understand that some pages will need to keep scripted UI in sync  
with movie playback, but this can be done very easily with a  
JavaScript timer:

	document.addEventListener('play', updateTimeDisplay, true);
	document.addEventListener('pause', updateTimeDisplay, true);

	function updateTimeDisplay()
	{
		var vid = document.getElementById('video');
	
		if (!vid.paused && !vid.ended && vid.networkState >  
HTMLMediaElement.HAVE_FUTURE_DATA)
			setTimeout(updateTimeDisplay, 200);
		
		// update display here
	}

   Using a timer also allows a script to update at exactly the  
frequency they need instead of at whatever frequency the UA happens to  
post events.

   Video and audio playback is already extremely CPU intensive, we  
shouldn't require the UA to burn extra cycles doing unnecessary work.

eric
Received on Friday, 31 October 2008 12:17:58 UTC

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