Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome/Webkit audio tag bug?

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

like image 374
Ronald Avatar asked Mar 11 '10 04:03

Ronald


2 Answers

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

Short audio files won't play.

like image 144
Ronald Avatar answered Sep 30 '22 03:09

Ronald


Try to host your audio file somewhere and try this:

audio = new Audio('http://www.yourhosting.com/chat.ogg');
audio.play();
like image 38
aygul Avatar answered Sep 30 '22 01:09

aygul