Question

I'm using a MediaPlayer in a TextureView to play a video in my Android app. When the MediaController is visible, it prevents me from selecting the ImageButtons I have below it in the same view (see image).

When the MediaController is hidden, I can select the buttons. I also tried moving the MediaController very far away from the buttons to see whether they were accidentally overlapping, but I still had the same problem.

How can I ensure that I can still select the ImageButtons even when the MediaController is visible?

enter image description here

Here is my layout file:

<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>

Here is how I create the controller:

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

I then associate it with a mediaPlayer here:

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

Solution

I wasn't able to figure this out completely, but this is my workaround.

I set the position of the MediaController using setY and setting it to a negative offset equal to the height of the buttons. I set up the MediaController in my onVideoSizeChanged (after I know the size of the video player)

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

This ends up looking like this:

enter image description here

You may notice that the play/pause and fastforward and rewind buttons are now gone; I wasn't able to get them to appear again. I still can't click on the image buttons when the mediaController is visible, but when I click anywhere in the view, the mediaController hides itself so the user essentially has to tap either button twice to get it to work. It's not great but better than what I had before.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top