问题
I'm currently building an app which shows a content with html tags. The content has a HTML5 video tag which shows video from an external source.
By using webview.loadDataWithBaseURL(), I load the html page. The webview shows the video along with the controls (play, stop, etc.). What I want to do is when I clicked the video, it will fire the android default mediaplayer intent downloading and playing the video source, not playing the video inline with the webview
By which way to achieve this task?
回答1:
Do like this
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://your_video_link), "video/mp4");
add permission android.permission.WRITE_EXTERNAL_STORAGE
回答2:
Use WebViewClient shouldOverrideUrlLoading
to detect the click
webView.setWebViewClient(new MyWebClient());
private class MyWebClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {}
来源:https://stackoverflow.com/questions/21873371/android-webview-video-to-play-in-mediaplayer