2012-02-02 65 views
7

我試圖在FULLSCREEN中的webview中播放嵌入的視頻時得到了NPE。它使用3.0蜂窩而不是ICS 4.0+。任何想法如何解決這個問題?不能以全屏模式播放的視頻

java.lang.NullPointerException 
    at android.webkit.PluginFullScreenHolder.show(PluginFullScreenHolder.java:85) 
    at android.webkit.WebView$PrivateHandler.handleMessage(WebView.java:8849) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:137) 
    at android.app.ActivityThread.main(ActivityThread.java:4424) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:511) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
    at dalvik.system.NativeStart.main(Native Method) 

任何建議將非常感激。由於

+1

如果你的Java堆棧跟蹤它的Android的錯誤。您可能會或可能沒有解決方法,很可能不會。希望在未來的ICS版本中進行修正。 – 2012-02-02 10:24:07

回答

1

問題是android操作系統中的一個錯誤。您需要解決此問題。
我正面臨同樣的問題。以下工作爲我工作。
希望這將幫助一些人:
創建FullscreenableChromeClient和 加入這一行:

WebView.setWebChromeClient(new FullscreenableChromeClient(this)); 


public class FullscreenableChromeClient extends WebChromeClient { 
     protected Activity mActivity = null; 

     private View mCustomView; 
     private WebChromeClient.CustomViewCallback mCustomViewCallback; 
     private int mOriginalOrientation; 

     private FrameLayout mContentView; 
     private FrameLayout mFullscreenContainer; 

     private static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 

     public FullscreenableChromeClient(Activity activity) { 
      this.mActivity = activity; 
     } 

     @Override 
     public void onShowCustomView(View view, int requestedOrientation, WebChromeClient.CustomViewCallback callback) { 
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 
       if (mCustomView != null) { 
        callback.onCustomViewHidden(); 
        return; 
       } 

       mOriginalOrientation = mActivity.getRequestedOrientation(); 
       FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView(); 
       mFullscreenContainer = new FullscreenHolder(mActivity); 
       mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS); 
       decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS); 
       mCustomView = view; 
       setFullscreen(true); 
       mCustomViewCallback = callback; 
       mActivity.setRequestedOrientation(requestedOrientation); 
      } 

      super.onShowCustomView(view, requestedOrientation, callback); 
     } 

     @Override 
     public void onHideCustomView() { 
      if (mCustomView == null) { 
       return; 
      } 

      setFullscreen(false); 
      FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView(); 
      decor.removeView(mFullscreenContainer); 
      mFullscreenContainer = null; 
      mCustomView = null; 
      mCustomViewCallback.onCustomViewHidden(); 
      mActivity.setRequestedOrientation(mOriginalOrientation); 
     } 

     private void setFullscreen(boolean enabled) { 
      Window win = mActivity.getWindow(); 
      WindowManager.LayoutParams winParams = win.getAttributes(); 
      final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN; 
      if (enabled) { 
       winParams.flags |= bits; 
      } else { 
       winParams.flags &= ~bits; 
       if (mCustomView != null) { 
        mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); 
       } else { 
        mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); 
       } 
      } 
      win.setAttributes(winParams); 
     } 

     private static class FullscreenHolder extends FrameLayout { 
      public FullscreenHolder(Context ctx) { 
       super(ctx); 
       setBackgroundColor(ctx.getResources().getColor(android.R.color.black)); 
      } 

      @Override 
      public boolean onTouchEvent(MotionEvent evt) { 
      return true; 
     } 
    } 
}