Webview crashes when displaying a youtube video

后端 未结 2 889
我寻月下人不归
我寻月下人不归 2021-01-06 01:50

After updating to 8.0 we get a crash so far we haven\'t seen before:

java.lang.NullPointerException: Attempt to invoke virtual method \'int android.graphics.         


        
相关标签:
2条回答
  • 2021-01-06 02:26

    Thanks to @breakline's answer, I got this issue worked around! Thanks! But instead of using decoding a bitmap, I just create an empty one and return that:

        setWebChromeClient(new WebChromeClient() {
            @Override
            public Bitmap getDefaultVideoPoster() {
                return Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
            }
        });
    
    0 讨论(0)
  • 2021-01-06 02:30

    Anyone still wondering instead of downvoting here is the actual fix to this. Since I spent quite some time on this I will post it here.

    You need to add the following to your WebChromeClient:

    webview.setWebChromeClient(new WebChromeClient() {
            @Override
            public Bitmap getDefaultVideoPoster() {
                Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.black);
                return icon;
            }
        });
    

    Any drawable is fine as long as it is an actual PNG file. If you use a drawable/xml you still get an exception.

    0 讨论(0)
提交回复
热议问题