我正在尝试在全屏上以html格式播放视频。当我单击视频方法中的全屏按钮时,会触发onShowCustomView。这是我的实现:

public void onShowCustomView(View view, CustomViewCallback callback) {
    super.onShowCustomView(view, callback);
    if (view instanceof FrameLayout) {
        customComponenet.addView(view, new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT,
                Gravity.CENTER));
        customComponenet.setVisibility(View.VISIBLE);
    }
}

其中customComponenet是FrameLayout放在我当前布局的顶部。 Wideo的表现不错,很明显,所有的接缝都还可以,但是它抛出了:
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235): FATAL EXCEPTION: main
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235): java.lang.NullPointerException
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at android.webkit.HTML5VideoFullScreen.switchProgressView(HTML5VideoFullScreen.java:320)
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at android.webkit.HTML5VideoView.setPlayerBuffering(HTML5VideoView.java:319)
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at android.webkit.HTML5VideoView.start(HTML5VideoView.java:85)
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at android.webkit.HTML5VideoViewProxy$VideoPlayer.onPrepared(HTML5VideoViewProxy.java:257)
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at android.webkit.HTML5VideoViewProxy.onPrepared(HTML5VideoViewProxy.java:278)
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at android.webkit.HTML5VideoView.onPrepared(HTML5VideoView.java:265)
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at android.webkit.HTML5VideoFullScreen.onPrepared(HTML5VideoFullScreen.java:164)
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:1456)
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at android.os.Handler.dispatchMessage(Handler.java:99)
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at android.os.Looper.loop(Looper.java:132)
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at android.app.ActivityThread.main(ActivityThread.java:4028)
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at java.lang.reflect.Method.invokeNative(Native Method)
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at java.lang.reflect.Method.invoke(Method.java:491)
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    08-27 22:16:07.520: ERROR/AndroidRuntime(7235):     at dalvik.system.NativeStart.main(Native Method)

我究竟做错了什么?

我的WebView设置:
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(PluginState.ON);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setDatabasePath("/data/data/" + App.class.getPackage().getName() + "/databases");
webView.getSettings().setSupportZoom(false);

我正在Galaxy Tab 10.1上进行测试,在默认浏览器上,它工作正常。我可以切换到全屏模式。此外,在我的应用中,当我播放嵌入的视频时,我只能听到声音,并且在视频应位于的区域下方看到状态栏,而在浏览器上,我可以看到嵌入在WebView和全屏中的视频。

编辑
https://github.com/novemberox/VideoFail这里是带有该错误的示例项目,您也可以在模拟器上打开它,因此您不需要真正的设备。

最佳答案

NPE看起来像HTML5VideoFullScreen中的错误,尽管我无法用模拟器重现它。

HTML5VideoFullScreen可能期望WebChromeClient#getVideoLoadingProgressView提供非空 View 。尝试重写该方法以返回非null的View对象(例如,布局中的虚假0x0 View),然后查看是否仍然崩溃。

10-07 23:22