android 6中的android webview youtube视频中的全屏模式问题

Posted

技术标签:

【中文标题】android 6中的android webview youtube视频中的全屏模式问题【英文标题】:Problem in full screen mode in android webview youtube video in android 6 【发布时间】:2020-03-24 23:44:01 【问题描述】:

android 6 有什么问题?请帮我解决这个问题。

logcat 第一行的 ************ 是一个短链接。要查看该链接,请单击here。

我尝试了许多其他链接,但在 android 6 中也存在同样的问题。

Logcat:

I/chromium: [INFO:CONSOLE(0)] "requestFullscreen() is deprecated on insecure origins, and support will be removed in the future. You should consider switching your application to a secure origin, such as HTTPS. See************* for more details.", source:  (0)
E/eglCodecCommon: glUtilsParamSize: unknow param 0x000085b5
E/eglCodecCommon: glUtilsParamSize: unknow param 0x000085b5
D/EGL_emulation: eglMakeCurrent: 0x9e67de60: ver 2 0 (tinfo 0x996d7240)
E/eglCodecCommon: glUtilsParamSize: unknow param 0x000085b5
W/AwContents: onDetachedFromWindow called when already detached. Ignoring
D/EGL_emulation: eglMakeCurrent: 0x9e67dda0: ver 2 0 (tinfo 0x996d7240)
D/EGL_emulation: eglMakeCurrent: 0x9e67de60: ver 2 0 (tinfo 0x996d7240)
D/EGL_emulation: eglMakeCurrent: 0x9e67dda0: ver 2 0 (tinfo 0x996d7240)
W/ResourceType: No known package when getting value for resource number 0x02040005
W/System.err: android.content.res.Resources$NotFoundException: String resource ID #0x2040005
        at android.content.res.Resources.getText(Resources.java:312)
        at android.content.res.Resources.getString(Resources.java:400)
        at android.content.Context.getString(Context.java:409)
        at org.chromium.content.browser.ContentVideoView.initResources(ContentVideoView.java:186)
        at org.chromium.content.browser.ContentVideoView.<init>(ContentVideoView.java:174)
        at org.chromium.content.browser.ContentVideoView.createContentVideoView(ContentVideoView.java:365)
        at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err:     at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
A/chromium: [FATAL:jni_android.cc(249)] Check failed: false. Please include Java exception stack in crash report
A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 9796 (m.di.battlegame)
E/eglCodecCommon: glUtilsParamSize: unknow param 0x000085b5
Process 9796 terminated.

Java 代码:

                webView=(WebView)findViewById(R.id.webview);

                webView.setWebChromeClient(new MyCrome()

                );



                webView.getSettings().setjavascriptEnabled(true);




                videourl="<html><body>"+description+"<br><iframe width=\"100%\" height=\"90%\" src=\"https://www.youtube.com/embed/"+videoid+"\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"></iframe></body></html>";

                webView.loadData(videourl,"text/html","utf-8");











public class MyCrome extends WebChromeClient 



        private View mCustomView;
        private WebChromeClient.CustomViewCallback mCustomViewCallback;
        protected FrameLayout mFullscreenContainer;
        private int mOriginalOrientation;
        private int mOriginalSystemUiVisibility;

        MyCrome() 


        public Bitmap getDefaultVideoPoster()
        
            if (HowtoActivity.this == null) 

                return Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
                //return null;
            
            //return BitmapFactory.decodeResource(HowtoActivity.this.getApplicationContext().getResources(), 2130837573);

            return Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
        

        public void onHideCustomView()
        



            ((FrameLayout)HowtoActivity.this.getWindow().getDecorView()).removeView(this.mCustomView);
            this.mCustomView = null;
            HowtoActivity.this.getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
            HowtoActivity.this.setRequestedOrientation(this.mOriginalOrientation);
            this.mCustomViewCallback.onCustomViewHidden();
            this.mCustomViewCallback = null;

        



        public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback)
        
            if (this.mCustomView != null)
            
                onHideCustomView();
                return;
            

            this.mCustomView = paramView;
            mCustomView.setBackgroundColor(Color.BLACK);
            this.mOriginalSystemUiVisibility = HowtoActivity.this.getWindow().getDecorView().getSystemUiVisibility();
            this.mOriginalOrientation = HowtoActivity.this.getRequestedOrientation();
            this.mCustomViewCallback = paramCustomViewCallback;
            ((FrameLayout)HowtoActivity.this.getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
            HowtoActivity.this.getWindow().getDecorView().setSystemUiVisibility(3846);
        
        


上面显示 webview youtube 视频的代码。 我在 android 9 和 android 10 上测试它完美。但在 android 6 它给我错误或异常显示在 logcat 上方

【问题讨论】:

相关:requestFullscreen() is deprecated on insecure origin, and support will be removed in the future 不适合我,|我也使用 https。 【参考方案1】:

我解决了我的问题。它只发生在模拟器中。

【讨论】:

以上是关于android 6中的android webview youtube视频中的全屏模式问题的主要内容,如果未能解决你的问题,请参考以下文章

关于富文本在Android中的应用以及遇到的坑

为啥Android WebView会显示黑屏?

Android Webview:获取输入类型文件元素的 ValueCallback

Android开发之WebView与js的数据传递

Android WebView 重定向问题

Android WebView 获取网页的标题