简体   繁体   中英

Unable to play audio in android emulator using html5 audio tag

I have developed one html5 page contains all htmls tags. I pushed that file into android emulator/device. when im trying to launching that page am able to view images and all but unable to play the audio.. is there any other reason.please help me asap..

Im able to play tat audio im desktop browser.

this is just alternet way to achieve goal to play audio from html file in android . because android 2.2 do not have support for audio tag of HTML5.

use Mediaplayer ( http://developer.android.com/reference/android/media/MediaPlayer.html ) of Android for playing audio. you can invoke function of android from javascript that you have written in HTML file..

this is example of how you can invoke function written in java file from javascript code (insted of ShowAndroidToast function, you can write code to play audio using mediaplayer object.)

  WebView webView = (WebView) findViewById(R.id.webview);
    webView.addJavascriptInterface(new WebAppInterface(this), "Android");
    --------------------------------
    public class WebAppInterface {

        Context mContext;
        /** Instantiate the interface and set the context */
        WebAppInterface(Context c) {
            mContext = c;
        }

        /** Show a toast from the web page */
        @JavascriptInterface
        public void showToast(String toast) {
            Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
        }
    }

    ---------------------------
    java sript code

    <input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />

    <script type="text/javascript">
        function showAndroidToast(toast) {
            Android.showToast(toast);
        }
    </script>

This way you invoke audio from Android code.

The Android(WebKit) 2.2 default browser technically supports HTML5 audio but it can't play any media files encoded with popular codecs. Because of browser vendors' inconsistent implementations of the HTML5 audio tag, you'll need to use JavaScript to accurately determine whether you can use native audio or a fallback.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM