Skip to content Skip to sidebar Skip to footer

Hide Play Pause Button Of Media Controller In Android

I have video View in my activity also having MediaController but I want to hide the play pause button from media controller. Here is my code: MediaController mediaController = new

Solution 1:

I have managed to achieve the same. By default Media Controller doesn't expose any method to hide the play/pause control. Hence we have to loop through the child views of Media Controller, get the desired view and do whatever you want to do with that view.

In my case, I did in following way ->

videoPlayer.setOnPreparedListener(newMediaPlayer.OnPreparedListener() {
        @OverridepublicvoidonPrepared(MediaPlayer mediaPlayer) {
              LinearLayoutviewGroupLevel1= (LinearLayout)  media_Controller.getChildAt(0);
            LinearLayoutviewGroupLevel2= (LinearLayout) viewGroupLevel1.getChildAt(0);
            Viewview= viewGroupLevel2.getChildAt(2);
            view.setVisibility(View.GONE);
            videoPlayer.start();
        }
    }); `

To explain my code, Basically Media Controller is a subclass of FrameLayout and it has one LinearLayout as a child viewgroup (viewGroupLevel1) at position 0, again viewGroupLevel1 contains two children view groups, out of which get the viewgroup (viewGroupLevel2) from viewGroupLevel1 at position 0. Now in viewGroupLevel2 get the view of position 2 which is actually an imagebutton (Play/Pause button). Now you can easily hide it. Cheers!

Solution 2:

You can see http://www.phonesdevelopers.com/1765331/

MediaControllermc=newMediaController(this);  
    mc.setVisibility(View.INVISIBLE);  
    videoView.setMediaController(mc);  

it's worked

Solution 3:

Try it ( not sure)

Use OnPreparedListener and in the callback onPrepared do your hide inderectly, like:

@OverridepublicvoidonPrepared(MediaPlayer mp) 
{
    intchilds= mediaController.getChildCount();
    for (inti=0; i < childs; i++)
    {
        Viewchild= mediaController.getChildAt (i);
        child.setVisibility (View.GONE);
    }
}

Post a Comment for "Hide Play Pause Button Of Media Controller In Android"