2

我正在构建一个应用程序,该应用程序依赖于能够在 WebView 中播放 Flash 并在发现一切正常,直到 Flash 视频全屏显示。请求全屏时,屏幕变黑,音频持续约 5 秒。

我最初发现屏幕变白了,但在下面的文章中调整了解决方案,这已经移动了球门柱。 Android ICS 4.0 将 Flash WebView 放入全屏调用 hideAll 方法?

final WebView mWebView = (WebView)findViewById(R.id.webview);
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setPluginState(WebSettings.PluginState.ON);
    webSettings.setJavaScriptEnabled(true);
    mWebView.requestFocusFromTouch();
    mWebView.setWebViewClient(new WebViewClient());

    mWebView.setWebChromeClient(new WebChromeClient(){
        public void onShowCustomView(View view, int requestedOrientation, WebChromeClient.CustomViewCallback callback){
            super.onShowCustomView(view, callback);   
            if(Build.VERSION.SDK_INT >=14) {
                if (view instanceof FrameLayout) {                  
                    mWebView.addView(view, new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    Gravity.CENTER));                   
                    mWebView.setVisibility(View.VISIBLE);
                }
            }
        }
    });

当全屏 Flash 视频开始时,我在 logcat 中看到以下内容。

08-11 15:09:47.435:V/VideoSurfaceView(23871):surfaceCreated

08-11 15:09:47.435: V/VideoSurfaceView(23871):surfaceChanged 格式=842094169,宽度=480,高度=690

以下答案参考了从浏览器实现类似于 BaseUI 类的 onShowCustomView 。有一个非常相似的方法叫做 showCustomView,我试图修改我的代码以添加 BaseUI 类的内容,令人惊讶的是我设法让我的代码编译和运行,但它并没有产生一点点差异。

尝试进入全屏模式android 4.0时Flash播放器崩溃

在此先感谢您的想法和帮助....

4

1 回答 1

2

经过更多的挖掘,我已经回答了我的问题,这使我进入了下一组问题,我将作为单独的问题发布。

以下代码将从 webView 全屏显示 Flash,只要 Flash 不请求更改方向。它还破坏了源 webView,因为在对“指定的孩子已经有父母”崩溃进行故障排除后,我被迫添加了 removeAllViews() 方法。

还将 WebView 作为最终实现以允许从重写的 WebChromeClient 方法进行访问会破坏需要访问此 WebView 的任何其他方法

public void startWebView(String url){
   final WebView mWebView = (WebView)findViewById(R.id.webview);
   final Context ctx = this;
   WebSettings webSettings = mWebView.getSettings();
        webSettings.setBuiltInZoomControls(true);
        webSettings.setPluginState(WebSettings.PluginState.ON);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setLoadWithOverviewMode(true);

        mWebView.requestFocusFromTouch();
        mWebView.setWebViewClient(new WebViewClient());

        mWebView.setWebChromeClient(new WebChromeClient(){
            protected WebView tempView;
            public void onShowCustomView(View view, int requestedOrientation, WebChromeClient.CustomViewCallback callback){
                super.onShowCustomView(view, callback);   
                if(Build.VERSION.SDK_INT >=14) {
                    if (view instanceof FrameLayout) {                  
                        mWebView.addView(view, new FrameLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        Gravity.CENTER));                   
                        mWebView.setVisibility(View.VISIBLE);
                    }
                }

                if (mCustomView != null) {
                    callback.onCustomViewHidden();
                    return;
                }

                mOriginalOrientation = activity.getRequestedOrientation();
                FrameLayout decor = (FrameLayout) activity.getWindow().getDecorView();
                mWebView.setVisibility(View.INVISIBLE);
                mFullscreenContainer = new FullscreenHolder(ctx);
                mWebView.removeAllViews();
                mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
                decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
                mCustomView = view;
                setFullscreen(true);

                mCustomViewCallback = callback;
                activity.setRequestedOrientation(requestedOrientation);

            }


            public void onHideCustomView() {
                if(debug==true)Log.d(name,"onHide start");
                mWebView.setVisibility(View.VISIBLE);


                if(debug==true)Log.d(name,"onHide ");
                if (mCustomView == null)
                    return;
                setFullscreen(false);
                FrameLayout decor = (FrameLayout) activity.getWindow().getDecorView();
                decor.removeView(mFullscreenContainer);
                mFullscreenContainer = null;
                mCustomView = null;
                mCustomViewCallback.onCustomViewHidden();
                if(debug==true)Log.d(name,"onHide callback");
                // Show the content view.
                activity.setRequestedOrientation(mOriginalOrientation);
                if(debug==true)Log.d(name,"onHide set orientation");
                mWebView.loadUrl("http://crooksandliars.com/susie-madrak/scott-brown-cries-over-poor-people-ge");
                if(debug==true)Log.d(name,"onHide start webview");
            }



            public void setFullscreen(boolean enabled) {
                Window win = activity.getWindow();
                WindowManager.LayoutParams winParams = win.getAttributes();
                final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
                if (enabled) {
                    winParams.flags |=  bits;
                } else {
                    winParams.flags &= ~bits;
                    if (mCustomView != null) {
                        mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
                    } else {
                        mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
                    }
                }
                win.setAttributes(winParams);
            }
        });

        mWebView.loadUrl(url);
}



   static class FullscreenHolder extends FrameLayout {

        public FullscreenHolder(Context ctx) {
            super(ctx);
            setBackgroundColor(00000);
        }

        @Override
        public boolean onTouchEvent(MotionEvent evt) {
            return true;
        }
    }
于 2012-08-11T18:20:01.023 回答