I want to make a simple browser app in android webview. Whenever I enter a website, if there's a video in that url, the video would be played into my custom video player automatically. Can anyone help me with this?
You must use javascript for this purpose. First, set a key in your content that load in your WebView, then with below code show any video with your custom VideoPlayer. Everywhere you have video at your url that load with webView, you must have like this:
"your_key:video_url"
Try this code:
web_view = (WebView) view.findViewById(R.id.web_view);
web_view.getSettings().setJavaScriptEnabled(true);
web_view.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//your_key is your javaScript key
final String videoUrl = url.replace("your_key:", "");
Intent intent=new Intent(getContext(), VideoPlayerActivity.class);
intent.putExtra("url",videoUrl);
startActivity(intent);
return false;
}
});
web_view.loadUrl(yourUrl);
As you see at above, when you click on any video, you get it's url and pass it to your videoPlayerActivity for showing with your custom videoPlayer.