Monday, 4 March 2019

Android WebView display only black screen with fullscreen video contained in an iframe

Issue

I am running a custom version of Cordova WebView within a React Native application. In the website, there's an embedded video, e.g from YouTube, my CDN, etc., that is wrapped within an <iframe> tag. When I clicked on the full screen, the screen went black and I only hear audio playing.

My attempts

I have attempted to fix with many suggestions on StackOverflow, such as:

  • android:hardwareAccelerated=true
  • Implemented custom onShowCustomView and onHideCustomView:
    @Override
    public void onShowCustomView(View v, WebChromeClient.CustomViewCallback cb) {

        if (mVideoView != null) {
            cb.onCustomViewHidden();
        } else {
            FrameLayout f = (FrameLayout) v;

            mVideoView = v;
            mWebView.setVisibility(View.GONE);

            f.getChildAt(0).setFocusable(true);

            mCustomView = new FrameLayout(mWebView.getContext());
            mCustomView.setVisibility(View.VISIBLE);
            mCustomView.addView(mVideoView);
            getWebViewParent().addView(mCustomView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            mVideoCallback = cb;
        }
    }

    @Override
    public void onHideCustomView() {
        super.onHideCustomView();
        if (mVideoView == null) {
            return;
        }

        mWebView.setVisibility(View.VISIBLE);
        mCustomView.setVisibility(View.GONE);
        mVideoView.setVisibility(View.GONE);

        mCustomView.removeView(mVideoView);
        getWebViewParent().removeView(mCustomView);

        mVideoCallback.onCustomViewHidden();

        mVideoView = null;
    }

Problems

The issue is not resolved and nothing seems to change. Following stack trace on debugger shows that: - The (only) child of the parameter View v is not focused - The class of the video view is the FullScreenView, which belongs to Android chromium.

What are the proposed solutions to resolve this issue? Thank you.



from Android WebView display only black screen with fullscreen video contained in an iframe

No comments:

Post a Comment