Android Pie(9.0)youtube全屏按钮在Webview中不起作用

时间:2019-04-21 07:05:15

标签: android webview fullscreen

直到Android O(8.0)版本都无法正常使用的webview-youtube全屏按钮的代码才适用于Android Pie(9.0)版本。

我尝试了stackoverflow,博客等中介绍的大多数方法,但对我而言不起作用。 我已经附上了一些我尝试过的链接。

Full screen option not available when loading YouTube video in WebView

https://blog.asamaru.net/2016/08/12/playing-html5-video-on-fullscreen-in-android-webview/

https://discourse.nativescript.org/t/android-video-fullscreen-not-working-in-webview/5441

我将WebChromeClient应用于我的Web视图。 并像这样覆盖onShowCustomView和onHideCustomView。 currentWebview,etcMenuLayout,linBottomBar是我的按钮的布局。 我尝试在youtube全屏模式下隐藏。 (它可以在Android Pie版本之前运行。)

            @Override
            public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) {
                Toast.makeText(mContext, "CLICKED", Toast.LENGTH_SHORT).show();
//                super.onShowCustomView(view, callback);
                mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                currentWebview.setVisibility(View.INVISIBLE);
                etcMenuLayout.setVisibility(View.GONE);
                linBottomBar.setVisibility(View.GONE);
                mFullscreenContainer = new FullscreenHolder(mActivity);
                customViewContainer = findViewById(R.id.customViewContainer);
                customViewContainer.setVisibility(View.VISIBLE);
                customViewContainer.addView(view);

            }

            @SuppressWarnings("deprecation")
            @Override
            public void onShowCustomView(View view, int requestedOrientation, WebChromeClient.CustomViewCallback callback) {
                this.onShowCustomView(view, callback);
            }

            @Override
            public void onHideCustomView() {
//                super.onHideCustomView();

                mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                currentWebview.setVisibility(View.VISIBLE);
                etcMenuLayout.setVisibility(View.GONE);
                linBottomBar.setVisibility(View.VISIBLE);
                customViewContainer.setVisibility(View.GONE);
                customViewContainer = null;
            }

在Android Pie上有什么解决方案吗?

0 个答案:

没有答案