0

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();     
    }    
}
scientiffic
  • 9,045
  • 18
  • 76
  • 149
  • It may relates to 'descendantFocusability" : Full answer here (http://stackoverflow.com/questions/15249632/android-custom-listview-with-imagebutton-is-not-getting-focus) – Mohsen Afshin Feb 20 '14 at 21:09
  • thanks for your help. I added descendantFocusability to the buttons as well as focusableInTouchMode and clickable (I edited the layout xml above) but it still doesn't work. – scientiffic Feb 20 '14 at 21:45
  • How are you creating/showing/hiding the MediaController? – marcone Feb 20 '14 at 22:08
  • I added the code above. – scientiffic Feb 20 '14 at 22:12
  • My guess would be that the padding you're specifying is causing this. Are you setting the padding in order to position the MediaController in the right spot? – marcone Feb 20 '14 at 22:38
  • yes, I need the mediacontroller to appear above the buttons. do you suggest any other way to do this? – scientiffic Feb 20 '14 at 22:39
  • I removed the padding and set the anchor view of the MediaController above the imageButtons, and I still got the same problem. – scientiffic Feb 20 '14 at 23:04
  • Have you looked at it with hierarchyviewer to see whether the MediaController view is overlapping the buttons? – marcone Feb 21 '14 at 23:42
  • Thanks for the suggestion; I hadn't used the Hierarchy Viewer before. Unfortunately, I have issues with loading the video through an emulator, and I'm not able to open the Hierarchy Viewer using my device. – scientiffic Feb 24 '14 at 18:21
  • What version of Android are you doing this on? There was a bug in earlier versions of Android where the MediaController would be positioned below its anchor view. This was fixed in one of the JellyBean releases I think, and the MediaController is now positioned inside its anchor view. (in other words: if you're running this on an older version of Android, the MediaController will be below the "media_holder" view, and therefore overlap the buttons) – marcone Feb 25 '14 at 16:28
  • I'm using honeycomb. Do you have any suggestions for how to fix this issue with honeycomb? – scientiffic Feb 25 '14 at 17:38

1 Answers1

0

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.

Community
  • 1
  • 1
scientiffic
  • 9,045
  • 18
  • 76
  • 149