Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing audio with HTML5 in Android browser

I want to play audio in the Android browser, using the html5 <audio> tag. It works fine in the iPhone browser, but not in Android. I'm using Android Virtual Device 4.0.3.

Does anyone know why?

The Android source:

webView.loadUrl("file:///android_asset/www/test.html");

The HTML file:

<audio controls="controls" format="mp3">
    <source src="achievement.mp3" /> 
</audio>

(i couldn't hear the audio with <embed> and <object> tags either)

like image 661
Saad Lamarti Avatar asked Jun 05 '12 16:06

Saad Lamarti


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.

How do I get HTML audio to play on my website?

Complete HTML/CSS Course 2022 To play sound file in the background on a web page, use the <embed>… </embed> element. Also, use the autoplay attribute. This will run music in the background whenever the page loads.

Does Opera GX support HTML5 audio?

Hi, I'm Simon Pieters, and I'm working with Quality Assurance for HTML5 video and audio at Opera. Opera 10.50 has now been released on Windows, and it supports the HTML5 video and audio elements.


2 Answers

I found the solution here Embed Background Audio in Android >= 2.3 Browser

<audio id="audio1" controls="controls" loop="loop" autoplay="autoplay" >
   <source src="scene1.mp3" type="audio/mpeg" />
   <source src="scene1.ogg" type="audio/ogg" />
</audio>

it's work for me :)

like image 133
Asyraf Azmin Avatar answered Oct 17 '22 19:10

Asyraf Azmin


I did a quick search and found this issue report on google code. It seems the tag is unsupported. However, the tag is and can play mp3 files. The down side is (if I read it correctly) that the controls are not available. Give it a read and let us know how you make out.

I found another question that has lots of different possible solutions: Check it out

like image 26
cstrutton Avatar answered Oct 17 '22 20:10

cstrutton