React Native Android WebView视频全屏(带旋转)

时间:2016-12-21 14:08:17

标签: android video webview react-native fullscreen

我目前为RN实施了一个原生模块,以便能够在全屏的网页浏览中播放html视频。

为此,我只是扩展ReactWebViewManager以将自定义setWebChromeClient设置为React Native Webview。

public class InTeachWebviewModule extends ReactWebViewManager {
    @Override
    public String getName() {
        return "RCTInTeachWebview";
    }

    @Override
    protected WebView createViewInstance(ThemedReactContext reactContext) {
        WebView root = super.createViewInstance(reactContext);
        root.setWebChromeClient(new VideoWebChromeClient(reactContext.getCurrentActivity(), root));
        return root;
    }
}

我是一个简单的CustomChromeClient:

public VideoWebChromeClient(Activity activity, WebView webView) {
    mWebView = webView;
    mActivity = activity;
}

@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
    if (mVideoView != null) {
        callback.onCustomViewHidden();
        return;
    }

    mVideoView = view;
    mCustomViewCallback = callback;

    view.setBackgroundColor(Color.BLACK);

    getRootView().addView(view, FULLSCREEN_LAYOUT_PARAMS);

    ((View)mWebView.getRootView()).setVisibility(View.GONE);
}
@Override
public void onHideCustomView() {
    if (mVideoView == null) {
        return;
    }
    ((View)mWebView.getRootView()).setVisibility(View.VISIBLE);
    mVideoView.setVisibility(View.GONE);

    getRootView().removeView(mVideoView);
    mVideoView = null;
    mCustomViewCallback.onCustomViewHidden();
}

如果没有屏幕旋转,它会很有用,但是一旦我调用mActivity.setRequestedOrientation(),就会调用onHideCustomView ...似乎调用setRequestedOrientation()即使所有网页浏览都会刷新在我的AndroidManifest中我已经

<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:theme="@style/SplashTheme"
    android:configChanges="orientation|screenSize">

有没有办法避免刷新?还是另一种旋转屏幕的方法?请注意,除了这种情况,我的应用程序只是纵向。

0 个答案:

没有答案