2012-05-14 119 views
3

訪問視頻對象上全屏模式我有一個簡單的佈局與一個FrameLayout裏顯示全屏視頻和網頁視圖:如何獲得在Android

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

<FrameLayout 
    android:id="@+id/frameLayout" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical|center_horizontal" > 
</FrameLayout> 

<WebView 
    android:id="@+id/webView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:clickable="true" /> 

的WebView顯示簡單的HTML5頁面定義的視頻。 onShowCustomView的

身體是:

@Override 
    public void onShowCustomView(View view, CustomViewCallback callback) { 
     super.onShowCustomView(view, callback); 
     FrameLayout frameLayout = (FrameLayout) findViewById(R.id.frameLayout); 

     FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
       ViewGroup.LayoutParams.FILL_PARENT, 
       ViewGroup.LayoutParams.FILL_PARENT, Gravity.CENTER); 
     frameLayout.removeAllViews(); 
     frameLayout.addView(view, layoutParams); 
     frameLayout.setVisibility(View.VISIBLE); 
    } 

我怎樣才能從onShowCustomView訪問視頻對象? 當我嘗試獲取framelayout的焦點孩子並將其投射到VideoView時,我得到一個ClassCastException(我有一個HTML5VideoFullScreen對象)。

請幫助。

回答

1

我一直注意到,從冰淇淋三明治(Android 4.0)開始,VideoView不用於視頻播放。有像你提到的HTML5VideoFullScreen這樣的新對象,它們有自己的MediaPlayers,而不是使用默認的VideoView。

爲什麼你需要VideoView?

+0

嗨 - 感謝您的回答。我需要控制視頻對象 - 主要是捕捉暫停和停止事件。 – durzy