启动媒体播放器的链接点击的web视图 [英] launch mediaplayer on link click in WebView

查看:76
本文介绍了启动媒体播放器的链接点击的web视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用的WebView加载一个网页的应用程序。一切正常,只是我无法在应用程序中播放任何视频文件。所以,我在找什么帮助上让我的应用程序启动媒体播放器,当我点击与.MP4结尾的链接。任何帮助和提示会大大AP preciated!

I have created an application that loads a website using WebView. Everything works fine except that I'm unable to play any video files within the application. So, what I'm looking for help on is getting my application to launch the mediaplayer when I click on a link ending with .mp4. Any help and tips would be much appreciated!

推荐答案

您需要覆盖的 shouldOverrideUrlLoading 方法,你webViewCient ...

You need to override the shouldOverrideUrlLoading method of your webViewCient...

final class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.endsWith(".mp4") {
            Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
            view.getContext().startActivity(intent);
            return true;
        } else {
            return super.shouldOverrideUrlLoading(view, url);
        }
    }
}

您分配给您的WebView:

... that you assign to your webview:

WebViewClient webViewClient = new MyWebViewClient();
webView.setWebViewClient(webViewClient);

编辑: 同样重要的是你增加:

also important that you add:

webView.getSettings().setAllowFileAccess(true);

要允许文件下载/流,如MP4文件。

to allow file downloads/streams such as mp4 files.

这篇关于启动媒体播放器的链接点击的web视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆