开发者

Implementing onShowCustomView on Android 3.1 throws exception in HTML5VideoFullScreen

I'm trying to play video in html on fullscreen. When I click on fullscreen button in video method onShowCustomView is fired. Here is my implementation:

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);
    }
}

Where customComponenet is FrameLayout placed on top of my current layout. Wideo is playing good, it's visibile and everything seams to be ok but it throws:

    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)

What am I doing wrong?

My WebView settings:

webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(PluginState.ON);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setDatabasePath开发者_如何学JAVA("/data/data/" + App.class.getPackage().getName() + "/databases");
webView.getSettings().setSupportZoom(false);

I'm testing on Galaxy Tab 10.1, on default browser this is working just fine. I can switch to fullscreen. Moreover in my app when I play video embeded I can hear only sound and see status bar below area where video should be, while on browser I can see video both embeded in WebView and on fullscreen.

EDIT https://github.com/novemberox/VideoFail here is sample project with that error, you can open it on emulator too, so you don't need to have real device.


The NPE looks like a bug in HTML5VideoFullScreen, though I was unable to reproduce it with my emulator.

Possibly HTML5VideoFullScreen is expecting a non-null View from WebChromeClient#getVideoLoadingProgressView. Try overriding that method to return a non-null View object (for instance, a bogus 0x0 View in your layout) and see if you still crash.


Don't forget to enable Hardware Acceleration !

You can find this at : Android Developer WebView sheet

HTML5 Video support

In order to support inline HTML5 video in your application, you need to have hardware acceleration turned on, and set a WebChromeClient. For full screen support, implementations of onShowCustomView(View, WebChromeClient.CustomViewCallback) and onHideCustomView() are required, getVideoLoadingProgressView() is optional.

So add this to your AndroidManifest.xml

<application 
  android:hardwareAccelerated="true" 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜