views:

900

answers:

3

I'm trying to get HTML5's audio tag to work in Chrome. The following code works flawlessly in Firefox, any ideas why it isn't working in Webkit?

<html>
  <head>
    <script type="text/javascript">
    function init(){
     audio = new Audio("chat.ogg");
     audio.play(); 
    }
    </script>
</head>
<body onload="init()">
</body>

I should also note that I tried this with an mp3 as well. Regardless of what format, whenever .play() is called on audio, Chrome responds with "undefined".

A: 

Are you using the release version of Chrome? With the current dev build on Linux[1], I get the same behavior as FF 3.7 alpha (well, once I unblocked it with noscript) and SeaMonkey 2.0; that is, the Ogg file plays, although not even the default controls appear. If it is a bug in Chrome or Webkit, it is apparently fixed for the next version.

[1] Chrome: 5.0.342.1 (Official Build 40461) dev, Webkit: 533.2

Kelly Clowers
Yep. I'm using 5.0.342.1 dev on OSX 10.5
Ronald
+1  A: 

Bug in Chrome, possibly Webkit as well: http://code.google.com/p/chromium/issues/detail?id=25972

Short audio files won't play.

Ronald
A: 

Try to host your audio file somewhere and try this:

audio = new Audio('http://www.yourhosting.com/chat.ogg');
audio.play();
aygul