3

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.

hphp95
  • 305
  • 3
  • 13

1 Answers1

0

Solution is correctly posted here: Webview and iFrame Video full screen issue

Basically the issue is that the VideoView shouldn't be in either the same hierarchy or subview hierarchy of the WebView. A quick implementation of onShowCustomView in Java would look like this:

mVideoView.setLayout(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
mVideoView.setVisibility(View.VISIBLE);
webViewRoot.addView(mVideoView);
webViewDirectParent.setVisibility(View.GONE);
hphp95
  • 305
  • 3
  • 13