2

I'm building an app that relies on being able to play Flash within a WebView and have after found everything works as expected up until the flash video is put into full screen. When request full screen, the screen goes black and the audio continues for about 5 seconds.

I initially was finding that the screen was going white, but adapted the solution in the article below, which has moved the goal post. Android ICS 4.0 Placing Flash WebView into full screen calls hideAll Method?

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);
                }
            }
        }
    });

When the full screen flash video starts I see the following in logcat.

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

08-11 15:09:47.435: V/VideoSurfaceView(23871): surfaceChanged format=842094169, width=480, height=690

The following answer makes reference to implementing onShowCustomView similar to the BaseUI class from the browser. There is a very similar method called showCustomView, I made an attempt to hack around my code to add the contents of the BaseUI class and surprising I managed to make my code compile and run, but it did not make a blind bit of difference.

flash player crashes when trying to enter fullscreen mode android 4.0

Thanks in advance for ideas and help....

Community
  • 1
  • 1
proudmatt
  • 197
  • 3
  • 8

1 Answers1

2

After some more digging I have answered my question, which has moved me onto the next set of problems, which I'll post as seperate questions.

The following code will display Flash in full screen from a webView, so long as Flash does not request an orientation change. It also breaks the source webView because I was forced to add the removeAllViews() method after troubleshooting "The specified child already has a parent" crashes.

Also having the implement the WebView as a final to allow access from the overridden WebChromeClient methods breaks any other methods that need to access this 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;
        }
    }
proudmatt
  • 197
  • 3
  • 8