0

在我的应用程序中,webviews 中有 webviews 和视频。但是视频没有播放 .. 下面是 webview 代码片段。

Web.setWebViewClient(new myWebClient()); 
Web.getSettings().setJavaScriptEnabled(true);
Web.getSettings().setPluginsEnabled(true);
Web.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
4

1 回答 1

2

2天后,寻找一种简单的方法来做这件事,对我来说,这是最好和最简单的解决方案:

public CustomViewCallback mCustomViewCallback;

@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
    super.onShowCustomView(view, callback);
    if (view instanceof FrameLayout) {
        FrameLayout customViewContainer = (FrameLayout) view;
        mCustomViewCallback = callback;
        if (customViewContainer.getFocusedChild() instanceof VideoView) {
            VideoView customVideoView = (VideoView) customViewContainer.getFocusedChild();
            try {
                Field mUriField = VideoView.class.getDeclaredField("mUri");
                mUriField.setAccessible(true);
                Uri uri = (Uri) mUriField.get(customVideoView);
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(uri, "video/*");
                mActivity.startActivity(intent);
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        mCustomViewCallback.onCustomViewHidden();
                    }
                });
            } catch (Exception e) {
            }
        }
    }
}

希望这有助于...

PS:适用于 YouTube

于 2013-03-11T10:24:44.510 回答