Make MediaController show without hide

brian picture brian · Dec 15, 2011 · Viewed 7.1k times · Source

I try to use MediaController to play music. I want the MediaController appear until the "back" button is pressed. Now I have try below code:

MediaController mediaController = new MediaController(this){
@Override
public void setMediaPlayer(MediaPlayerControl player) {
super.setMediaPlayer(player);
this.show();
}
@Override
public void show(int timeout) {
super.show(0);
}
//instead of press twice with press once "back" button to back
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if(event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
Activity a = (Activity)getContext();
a.finish();
}
return true;
}
}; 

But it still one trouble while the MediaController visible. When the MediaController appear touch the screen, the MediaController will hide. I also already try below code:

@Override
public boolean onTouchEvent(MotionEvent event) {
Log.d("screen","touch");
return true;
}

But it did not work. The string did not show in Logcat. Anyone has idea to do it?

Answer

Chet picture Chet · Dec 15, 2011

Override this method also inside media controller

@Override
            public void hide() {
                // TODO Auto-generated method stub
                super.show();
            }