flash player crashes when trying to enter fullscreen mode android 4.0

前端 未结 3 1557
执念已碎
执念已碎 2020-12-21 17:37

So I\'ve created an android app that plays video from blip.tv and various other flash-enabled websites. I use a Webview to display the video. Here is my code:

相关标签:
3条回答
  • 2020-12-21 17:50

    This happens in ICS because the show() method in android.webkit.PluginFullScreenHolder gets called when trying to go to fullscreen mode. This method does the following:

    WebChromeClient client = mWebView.getWebChromeClient();
    client.onShowCustomView(mLayout, mOrientation, mCallback);
    

    If you do not set the WebChromeClient on your WebView, you will get an NPE.

    This fixed our crash, however the WebView disappears and the fullscreen video is not shown.

    See: Android ICS 4.0 Placing Flash WebView into full screen calls hideAll Method?

    *** Update:

    Ultimately, in order to get my WebView to play flash videos in full screen mode I had to implement the onShowCustomView() method in my WebChromeClient in a fashion similar to what was done in the source code for the Android browser. The implementation of that method that I used for inspiration was in the BaseUI class:

    https://github.com/android/platform_packages_apps_browser/blob/master/src/com/android/browser/BaseUi.java

    I don't fully understand exactly what is happening here. I also wish I understood why the developers on ICS decided to require this method to be implemented. I wish I knew the value, or what problem this solved. In past versions, this fullscreen mode "just worked" now it requires a lot of digging.

    0 讨论(0)
  • 2020-12-21 18:01

    Okay, so I think this is an android 4.0.2 / flash player problem, because other apps like browser and dolphin mini crash when flash is put into full screen mode.

    0 讨论(0)
  • 2020-12-21 18:09

    I was facing the same problem. I asked and got the following answer which works for me.
    Hope this will help some people:
    Create the FullscreenableChromeClient and add this line:

    WebView.setWebChromeClient( new FullscreenableChromeClient(this));
    


        public class FullscreenableChromeClient extends WebChromeClient {
            protected Activity mActivity = null;
    
            private View mCustomView;
            private WebChromeClient.CustomViewCallback mCustomViewCallback;
            private int mOriginalOrientation;
    
            private FrameLayout mContentView;
            private FrameLayout mFullscreenContainer;
    
            private static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    
            public FullscreenableChromeClient(Activity activity) {
                this.mActivity = activity;
            }
    
            @Override
            public void onShowCustomView(View view, int requestedOrientation, WebChromeClient.CustomViewCallback callback) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    if (mCustomView != null) {
                        callback.onCustomViewHidden();
                        return;
                    }
    
                    mOriginalOrientation = mActivity.getRequestedOrientation();
                    FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
                    mFullscreenContainer = new FullscreenHolder(mActivity);
                    mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
                    decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
                    mCustomView = view;
                    setFullscreen(true);
                    mCustomViewCallback = callback;
                    mActivity.setRequestedOrientation(requestedOrientation);
                }
    
                super.onShowCustomView(view, requestedOrientation, callback);
            }
    
            @Override
            public void onHideCustomView() {
                if (mCustomView == null) {
                    return;
                }
    
                setFullscreen(false);
                FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
                decor.removeView(mFullscreenContainer);
                mFullscreenContainer = null;
                mCustomView = null;
                mCustomViewCallback.onCustomViewHidden();
                mActivity.setRequestedOrientation(mOriginalOrientation);
            }
    
            private void setFullscreen(boolean enabled) {
                Window win = mActivity.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);
            }
    
            private static class FullscreenHolder extends FrameLayout {
                public FullscreenHolder(Context ctx) {
                    super(ctx);
                    setBackgroundColor(ctx.getResources().getColor(android.R.color.black));
                }
    
                @Override
                public boolean onTouchEvent(MotionEvent evt) {
                return true;
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题