2014-02-20 30 views
0

我在TextureView中使用MediaPlayer在我的Android應用程序中播放視頻。當MediaController可見時,它阻止我在同一視圖中選擇我下面的ImageButton(請參閱圖像)。MediaController阻止使用ImageButtons

當的MediaController是隱藏的,我可以選擇的按鈕。我還嘗試將MediaController移動到離按鈕很遠的位置,以查看它們是否意外重疊,但我仍然遇到同樣的問題。

我怎麼能保證我仍然可以選擇ImageButtons即使是的MediaController可見?

enter image description here

這是我的佈局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/black" 
android:orientation="vertical" 
tools:context=".MediaPreview" > 

<FrameLayout 
    android:id="@+id/media_holder" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/bottom_button_image_preview" 
    android:layout_alignParentTop="true" 
    android:background="@color/black" 
    android:gravity="center" > 

    <FrameLayout 
     android:id="@+id/main_content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/black" > 
    </FrameLayout> 

     <TextureView 
      android:id="@+id/s3_video" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:rotation="0" 
      /> 

</FrameLayout> 

<ProgressBar 
    android:id="@+id/media_progress" 
    style="?android:attr/progressBarStyleLarge" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" /> 

<LinearLayout 
    android:id="@+id/bottom_button_image_preview" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:background="@color/white" 
    android:gravity="center_horizontal" 
    android:orientation="horizontal" 
    android:focusableInTouchMode="true" 
    android:clickable="true" 
    android:descendantFocusability="blocksDescendants" > 

    <ImageButton 
     android:id="@+id/delete_imagePreview" 
     android:layout_width="wrap_content" 
     android:layout_height="@dimen/bottom_button_height" 
     android:layout_marginRight="1dp" 
     android:layout_weight="0.3" 
     android:adjustViewBounds="true" 
     android:background="@drawable/custom_button_blue" 
     android:contentDescription="@string/delete_imagePreview" 
     android:maxHeight="60dp" 
     android:maxWidth="60dp" 
     android:scaleType="fitCenter" 
     android:src="@drawable/ic_action_discard" 
     android:focusableInTouchMode="true" 
     android:clickable="true" 
     android:descendantFocusability="blocksDescendants"> 
    </ImageButton> 

    <ImageButton 
     android:id="@+id/okay_imagePreview" 
     android:layout_width="wrap_content" 
     android:layout_height="@dimen/bottom_button_height" 
     android:layout_weight="0.3" 
     android:adjustViewBounds="true" 
     android:background="@drawable/custom_button_blue" 
     android:contentDescription="@string/okay_imagePreview" 
     android:maxHeight="60dp" 
     android:maxWidth="60dp" 
     android:scaleType="fitCenter" 
     android:src="@drawable/ic_action_accept_white" 
     android:focusableInTouchMode="true" 
     android:clickable="true" 
     android:descendantFocusability="blocksDescendants"> 
    </ImageButton> 
</LinearLayout> 

這裏是我創建控制器:

// set up mediacontroller 
    videoController = new MediaController(this); 
    videoControllerExists = true; 
    videoController.setAnchorView(mediaHolder); 
    videoController.setPadding(0, 0, 0, bottomButtonHeight); 

我然後將其與媒體播放此處關聯:

@Override 
public void onPrepared(MediaPlayer mp) { 
    if(isAmazon && mediaURL.length() > 0){ 
     videoController.setMediaPlayer(this); 
     videoController.setEnabled(true); 
     videoController.show();  
    }  
} 
+0

它可能與'descendantFocusability'有關:完整答案here(http://stackoverflow.com/questions/15249632/android-custom-listview-with-imagebutton-is-not-getting-focus) –

+0

感謝您的幫助我加入descendantFocusability的按鈕以及focusableInTouchMode和點擊(編輯我上面的佈局XML),但它仍然無法正常工作。 – scientiffic

+0

你是如何創建/顯示/隱藏的MediaController? – marcone

回答

0

我不能完全弄清楚了這一點,但是這是我的解決辦法。

我使用SETY並將其設置爲一個負偏移等於該按鈕的高度設置的MediaController的位置。我將在我的onVideoSizeChanged中的MediaController(之後我知道了視頻播放器的大小)

s3VideoPlayer.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() { 

        @Override 
        public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { 

         // set up mediacontroller 
         videoController = new MediaController(MediaPreview.this); 
         videoControllerExists = true;   
         videoController.setAnchorView(mediaHolder); 
         videoController.setY(-bottomButtons.getHeight()); 
         videoController.bringToFront(); 
         videoController.requestFocus(); 
         mediaProgress.setVisibility(View.GONE); 
        } 
       }); 
       s3VideoPlayer.start(); 

這結束這樣看:

enter image description here

你可能會注意到,播放/暫停並且快進和快退按鈕現在消失了;我無法讓他們再次出現。當mediaController可見時,我仍然無法點擊圖像按鈕,但是當我點擊視圖中的任何位置時,mediaController會自行隱藏,因此用戶實質上必須點擊兩個按鈕才能使其工作。這不是很好,但比以前更好。