Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android launch mediplayer for videos from a webview?

I have a webview, if the user clicks on a link, it opens in the same webview (I controll that with shouldOverrideUrlLoading()) but if it is a video link (mp4, 3gp) it does not launch the media player to reproduce the video (as it does in the normal browser app). How o force the media player to launch when a video link is clicked inside a webview?

Thanks!

like image 740
yusev segunpta Avatar asked Feb 28 '23 13:02

yusev segunpta


1 Answers

In this case you will need to execute an Intent to load an external video url. This also conveniently allows user to return to the previous view ( activity ) without any problem. See code below....

 /*-----------------------------------------------------------------------------------------------
 *  WebViewClientHandler() allows for overriding default phone web browser so we can load in gui
 *----------------------------------------------------------------------------------------------*/
private class WebViewClientHandler extends WebViewClient {
  public boolean shouldOverrideUrlLoading(WebView view, String url) {

    Uri uri = Uri.parse("http://YOUTSTREAM.FLV");
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);

    startActivity(intent);
        return true;
   }
}
like image 111
Psypher Avatar answered Mar 07 '23 07:03

Psypher