Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing html5 audio in android browser

Tags:

I have a javascript that plays audio in the browser, using the html5 <audio> tag. It works fine in the iPhone browser, but not in Android. (Testing using a htc desire with android 2.1.) Anyone know why?

My code:

   function playHTML5(sound, soundcv){
                // sound = url to m4a audio file
                // soundcv = div in which the audioplayer should go

  var audio = document.createElement('audio');
  audio.src = sound;
  audio.controls = "controls";
  if (currentSound != null){
   soundcv.replaceChild(audio,currentSound);
  } else {
   soundcv.appendChild(audio);
  }
  currentSound = audio;
 }

By the way, I am also trying to enlarge the audio button that shows up in the iphone (the default one is quite small), with no luck so far - would be grateful for any ideas!

like image 508
Anders Sundnes Løvlie Avatar asked Jun 18 '10 11:06

Anders Sundnes Løvlie


People also ask

Can I play audio in HTML5?

HTML5 features include native audio and video support without the need for Flash. The HTML5 <audio> and <video> tags make it simple to add media to a website. You need to set src attribute to identify the media source and include a controls attribute so the user can play and pause the media.

Does Opera GX support HTML5 audio?

The latest version of Opera supports the HTML5 video and audio elements.

Does HTML5 support MP3?

Currently, there are 3 supported “audio formats” for the HTML5 “audio” tag: . mp3, . ogg, and . wav.


2 Answers

The latest Android browser in FroYo does not yet support the HTML5 audio element. This is not a bug, rather a feature that has yet to be implemented. It may come in Gingerbread.

Update: The Gingerbread browser has the audio element.

like image 82
Pierre-Antoine LaFayette Avatar answered Sep 18 '22 14:09

Pierre-Antoine LaFayette


Here is link to Google Android bug, which filed for lack of support of AUDIO tag in Android. Please, vote on it.

http://code.google.com/p/android/issues/detail?id=10546

BTW, there is work around, which let you play natively MP3 in Android 1.6 .. 2.2, like that:

<video src="test.mp3" onclick="this.play();"></video>
like image 28
Slavik Avatar answered Sep 16 '22 14:09

Slavik