Does Android launch media player for video from web view?

I have a webview, if the user clicks on the link, it opens in the same webview (I manage this with shouldOverrideUrlLoading ()), but if it is a video link (mp4, 3gp), it does not start the media player to play the video (like in a normal browser). How to make the media player start when you click a video link inside a web view?

Thanks!

+4
source share
5 answers

In this case, you will need to execute Intent to load the external video. It also allows the user to easily return to the previous view (activity). 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; } } 
+4
source

It probably doesn’t matter now, but what you see in the browser is not a media player, but Android Video. When you click on a video call link, an onShowCustomView (View view, WebChromeClient.CustomViewCallback callback) call onShowCustomView (View view, WebChromeClient.CustomViewCallback callback) is called in WebChromeClient. It is the obligation of the application to display this view and then inform WebView that the view is no longer required.

+2
source

I meant that when the URL points to a video file, I would like the media player to play it. Every other URL is handled by the webview, and that’s fine, but when the URL points to a video file, nothing happens when I try to download that URL.

+1
source

you should try this

 WebView webView = (WebView) findViewById(R.id.embeddedWebView); webView.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long size) { Intent viewIntent = new Intent(Intent.ACTION_VIEW); viewIntent.setDataAndType(Uri.parse(url), mimeType); try { startActivity(viewIntent); } catch (ActivityNotFoundException ex) { Log.w("YourLogTag", "Couldn't find activity to view mimetype: " + mimeType); } } }); 
+1
source

First of all, as far as I know, Android only supports rtsp playback. Therefore, onclick links, give document.location.href = "rtsp: // your video";

0
source

Source: https://habr.com/ru/post/1301873/


All Articles