2011-12-28 176 views
2

所以我創建了一個Android應用程序,從blip.tv和其他各種支持Flash的網站上播放視頻。我使用Webview來顯示視頻。這裏是我的代碼:flash播放器崩潰4.0

try{ 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 


     view = new WebView(this); 
     view.getSettings().setPluginsEnabled(true); 
     view.getSettings().setPluginState(WebSettings.PluginState.ON); 

     view.getSettings().setJavaScriptEnabled(true); 
     view.getSettings().setLoadWithOverviewMode(true); 
     view.getSettings().setUseWideViewPort(true); 
     view.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); 
     view.setScrollbarFadingEnabled(true); 


     // get the html code 
     String html = getIntent().getStringExtra("VIDEO_CONTENT"); 

     view.loadData(html, "text/html", null); 
     setContentView(view); 
    } 
    catch(Exception e){ 

    } 

問題是與Android 4(冰淇淋三明治)。當我嘗試將應用程序置於全屏模式時,應用程序崩潰。然而,該應用不會在android 2.3或3.0上崩潰。任何想法來解決這個問題?

回答

1

好了,所以我覺得這是一個Android 4.0.2/Flash播放器的問題,因爲其他應用程序,如browserdolphin mini崩潰時,閃光燈被置於全屏模式。

4

這發生在ICS中,因爲android.webkit.PluginFullScreenHolder中的show()方法在嘗試轉到全屏模式時被調用。此方法執行以下操作:

WebChromeClient client = mWebView.getWebChromeClient(); 
client.onShowCustomView(mLayout, mOrientation, mCallback); 

如果不設置WebChromeClientWebView,你會得到一個NPE。

這種固定我們的崩潰,但是WebView中消失,全屏視頻沒有顯示。

參見:Android ICS 4.0 Placing Flash WebView into full screen calls hideAll Method?

***更新:

最終,爲了得到我的WebView播放Flash影片在全屏模式下,我不得不實施onShowCustomView()方法在我WebChromeClient類似的方式到在Android瀏覽器的源代碼中完成了什麼。我用靈感該方法的實現是在BaseUI類:

https://github.com/android/platform_packages_apps_browser/blob/master/src/com/android/browser/BaseUi.java

我不完全明白到底這裏發生了什麼。我也希望我明白爲什麼ICS的開發者決定要求實施這種方法。我希望我知道價值,或者解決了什麼問題。在過去的版本中,這種全屏模式「剛剛工作」,現在需要大量的挖掘。

+0

酷感謝我給這是一個嘗試。 – Darcy 2012-02-07 22:38:30

+2

能否請您通過上面我終於取得了Flash播放視頻全屏代碼共享您的解決方案,謝謝 – user634545 2012-03-14 11:14:40

2

我面臨同樣的問題。我詢問並得到了適合我的以下答案。
希望這將幫助一些人:
創建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; 
     } 
    } 
} 
+1

。 – 2013-06-27 18:32:56