Android WebView全屏播放Flash / YouTube视频

时间:2013-04-23 21:53:49

标签: android android-widget youtube android-webview

我想要完成的是当WebView中存在嵌入式iframe YouTube视频并且用户开始播放视频然后点击全屏按钮时,我希望它以全屏显示Dialog,与https://code.google.com/p/html5webview/source/browse/trunk/HTML5WebView/src/org/itri/html5webview/HTML5WebView.java

之类的建议不同

我在WebViewDialog中都播放了视频,但是,全屏对话框中没有播放器控件。以下是目前为止在对话框中播放的被黑客入侵的代码。

    webView.setWebChromeClient(new WebChromeClient() {
            View mVideoProgressView;

            Bitmap mDefaultVideoPoster;

            Dialog fullScreenDialog;

            WebChromeClient.CustomViewCallback mCustomViewCallback;

            @Override
            public void onShowCustomView(View view, CustomViewCallback callback) {
                super.onShowCustomView(view, callback);
                if (view instanceof FrameLayout) {


                    FrameLayout frameLayout = (FrameLayout) view;
                    mCustomViewCallback = callback;
                    fullScreenDialog = new Dialog(DemoActivity.this, R.style.full_screen_dialog);
//                    fullScreenDialog = new Dialog(DemoActivity.this, R.style.Dialog_Fullscreen);
                    LinearLayout linearLayout = (LinearLayout) getLayoutInflater().inflate(R.layout.full_screen_video_view, null);
                    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                    params.gravity = Gravity.CENTER;

                    SurfaceView surfaceView = (SurfaceView)frameLayout.getFocusedChild();
                    surfaceView.bringToFront();
                    surfaceView.setZOrderMediaOverlay(true);
                    surfaceView.setZOrderOnTop(true);
                    surfaceView.setLayoutParams(params);

//                    frameLayout.removeAllViews();
//                    linearLayout.addView(surfaceView);

//                    fullScreenDialog.setContentView(view, params);
                    frameLayout.removeAllViews();
                    fullScreenDialog.setContentView(surfaceView);
                    fullScreenDialog.show();
                }
            }

            @Override
            public void onHideCustomView() {
                if (fullScreenDialog != null && fullScreenDialog.isShowing()) {
                    fullScreenDialog.dismiss();
                }
                if (mCustomViewCallback != null) {
                    mCustomViewCallback.onCustomViewHidden();
                    mCustomViewCallback = null;
                }
            }

            @Override
            public Bitmap getDefaultVideoPoster() {
                if (mDefaultVideoPoster == null) {
                    mDefaultVideoPoster = BitmapFactory.decodeResource(getResources(), R.drawable.default_video_poster);
                }
                return mDefaultVideoPoster;
            }

            @Override
            public View getVideoLoadingProgressView() {
                if (mVideoProgressView == null) {
                    LayoutInflater inflater = getLayoutInflater();
                    mVideoProgressView = inflater.inflate(R.layout.video_loading_progress, null);
                }
                return mVideoProgressView;
            }
        });

我的full_screen_dialog风格很简单:

<style name="full_screen_dialog">
        <!--<item name="android:windowFrame">@null</item>-->
        <!--<item name="android:windowIsFloating">true</item>-->
        <!--<item name="android:windowContentOverlay">@null</item>-->
        <!--<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>-->
        <!--<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>-->
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowNoTitle">true</item>
    </style>

WebView设置启用了javascript和插件。

有许多类似的问题已发布,但没有人试图在全屏幕对话框中打开视频。任何帮助将不胜感激!

0 个答案:

没有答案