Webview crashes when displaying a youtube video

后端 未结 2 917
我寻月下人不归
我寻月下人不归 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: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.

提交回复
热议问题