WebView NOT opening android default video player?

后端 未结 2 1827
时光说笑
时光说笑 2020-12-11 18:48

when I view this page on my android device\' default web browser and click the first video, it triggers the default video player of my device. It loads and play.

How

相关标签:
2条回答
  • 2020-12-11 19:20

    If you are getting a html5 video tag in the WebView then the above code (using WebViewClient) will not be called, instead you will have to handle it with WebChromeClient as shown in the bellow link

    How to play a video in a webview with android?

    I have tried it out and it worked well :)

    the above code (using WebViewClient) is useful only when we have to handle a redirect request to another page via user click on anchor tag or through any hyperlink in the WebView

    0 讨论(0)
  • 2020-12-11 19:31

    You have to attach your own WebViewClient and override shouldOverrideUrlLoading() if you detect a URL with a supported video mimetype return true and then launch the default activity with the URL. Here is an untested sample.

    mWebView.setWebViewClient(new WebViewClient(){
    
    public boolean shouldOverrideUrlLoading(Webview view, String url){
         if(url.endsWith(".mp4") || url.endsWith("some other supported type")){
              Intent i = new Intent(Intent.ACTION_VIEW);
              i.setData(Uri.parse(url));
              startActivity(i); //warning no error handling will cause force close if no media player on phone.
              return true;
         }
         else return false; 
    }});
    

    hope this helps.

    0 讨论(0)
提交回复
热议问题