android: hiding media controller functions

Farhan  picture Farhan · Jul 13, 2011 · Viewed 7.2k times · Source

I have a videoview and when the video starts, the media controller is shown for 3 seconds. I want to hide the media controller unless i tap on the screen. I tried

MediaController mc= new MediaController();
mc.hide();
Videoview.setMediaController(mc);
..
..
..

But it didn't work.. Any suggestions please?

Answer

posit labs picture posit labs · Oct 5, 2011

This isn't really a solution to hiding the MediaController, but if you want to get rid of the thing altogether, do this:

videoView.setMediaController(null);

You can have it initially hidden by doing the above, and then when you want it to show (onClick or onTouch or whatever), just make a new MediaController and set it on the videoView. I added a boolean to prevent the action from happening more than once.

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        if (controllerCreated == false) {
            videoView.setMediaController(mc);
            mc.show();
            controllerCreated = true;
        }
        return true;
    } else {
        return false;
    }
}