Android webview video to play in mediaplayer

我怕爱的太早我们不能终老 提交于 2020-01-14 05:05:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!