Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 <audio> tag on Android

I have found many threads discussing the support of tag on Android. So far it looks, that even Android Froyo 2.2 cannot play audio (i have made tests on nexus One).

According to the www.html5test.com web page, the tag itself is supported, but no codecs are in the browser (mp3, ogg..). So how I can solve the problem?

So far I see only one solution, use the embedded Flex or Flash player, which can stream mp3. Is that correct? Is that the only way I can play the .mp3 or other audio stream in Android web browser?

Does Android 2.3 Gingerbread support some audio stream???

Thanks a lot BR STeN

Added later:The working solution I finally used is a small Flex .swf for streaming. It can be pretty easily integrated with the HTML web page (Flex-Javascript communication works pretty well). The only problem is that on some phones the Flash Player is not reinstalled and must be downloaded from Android Market first.

Added even later: Well, the <audio> element is buggy even on Android 2.3 - I do not know what are doing in Google that such a simple thing is a problem. Using the Flex Player is okey, but the problem is that on some phones the Adobe Flash player cannot be installed from Android market, because there are some Adobe HW requirements like 1Ghz CPU, etc. Some vendors like HTC are providing the own Flash players, but those are pretty bad and do not work correctly with the AS 3.0... So far everything works perfectly especially on Samsung phones (like Nexus S or Galaxy S).

like image 202
STeN Avatar asked Feb 04 '11 06:02

STeN


2 Answers

What you dug up agrees with what I've run into as well. 2.2 supports the audio tag but has no codecs to back it, this is apparently a bug that's been fixed in releases beyond Froyo:

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

I've used the audio tag with an mp3 file on my Nexus S, it's working correctly there (for the most recent firmware release at least).

like image 69
mikerowehl Avatar answered Oct 06 '22 09:10

mikerowehl


I forgot to ask first. Are you thinking on developing an Android application or just a regular web-app? Cause for this solution you would need Android code.

If you're not considering using Android code, then you can skip the rest of the message, sorry!

==================================================================================

Here it's some trick: You can use regular links to your audio files, or use javascript to redirect to one of the files (if you let Javascript do it), then override the Url loading, like this:

mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
mWebView.setWebViewClient(new WebViewClient(){
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.endsWith(".ogg")){
            Log.d(TAG, "Reproducir archivo OGG");
            Uri tempPath = Uri.parse(url);
            MediaPlayer player = MediaPlayer.create(WebViewVideo.this, tempPath);
            player.start();
            return true;
        }else{
            return super.shouldOverrideUrlLoading(view, url);
        }
    }

});

Hope this helps, it does for me!

Regards.

like image 27
mdelolmo Avatar answered Oct 06 '22 10:10

mdelolmo