[whatwg] Help with HTML5 Audio

Ian Hickson ian at hixie.ch
Fri Aug 3 18:38:32 PDT 2007


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).

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



More information about the whatwg mailing list