Reputation: 41
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!
Upvotes: 4
Views: 10440
Reputation: 31
It's probably irrelevant now, but what you see is in the browser is not the media player, but an Android owned VideoView. When a video link is clicked a call to onShowCustomView (View view, WebChromeClient.CustomViewCallback callback)
in WebChromeClient is made. It's the application obligation to display that view and then inform the WebView that the View is no longer needed.
Upvotes: 3
Reputation: 9023
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);
}
}
});
Upvotes: 1
Reputation: 53
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;
}
}
Upvotes: 4
Reputation: 11
First of all, as far as I know, Android supports rtsp playback only. So onclick of the link, give document.location.href="rtsp://your video url";
Upvotes: 0
Reputation: 11
I meant that when the url is pointing to a video file, I'd like the mediaplayer to reproduces it. Every other URL is being handled by the webview, and that is OK but when the URL is pointing to a video file, nothing happens when I try to load that url.
Upvotes: 1