HTML5 <audio> tag not working in Android Webview

后端 未结 2 1913
悲哀的现实
悲哀的现实 2020-12-29 00:02

the HTML5 audio tag doesn\'t seem to work in the web view if the source file is stored locally. i.e.

2条回答
  •  萌比男神i
    2020-12-29 00:26

    this is just alternet way to achieve goal to play audio from html file

    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

    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
    
    
    
    
    

    This way you invoke audio from Android code.

提交回复
热议问题