W3C home > Mailing lists > Public > whatwg@whatwg.org > August 2007

[whatwg] Help with HTML5 Audio

From: Ian Hickson <ian@hixie.ch>
Date: Sat, 4 Aug 2007 01:38:32 +0000 (UTC)
Message-ID: <Pine.LNX.4.64.0708040125100.25485@dhalsim.dreamhost.com>
On Fri, 22 Sep 2006, Jeff Schiller wrote:
> I need a solution that will work whether the sound is cached or not. Is 
> this a problem in the spec or a problem with my understanding of this 
> object or event handlers?

The spec changed quite a bit, but now you should be able to do:

   var sound = new Audio("foo.ogg");
   sound.onload = function() { sound.play() };

This will get the while file fully downloaded, then play it. You can also 
do things like:

   var sound = new Audio("foo.ogg");
   sound.oncanplaythrough = function() { sound.play() };

...if you are willing to bet on network quality (it'll fire as soon as 
the user agent things that network conditions are such that playback can 
start and then go through to the end without stalling).

Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Friday, 3 August 2007 18:38:32 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:58:57 UTC