Make MediaController show without hide

时光总嘲笑我的痴心妄想 提交于 2019-12-05 01:19:31

问题


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?


回答1:


Override this method also inside media controller

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



回答2:


If you want to keep the hide() method but not have the controller disappearing every time a control is used :

this.mediaController = new MediaController(this){
    @Override
    public void show(int timeout) {
        super.show(0);
    }
};


来源:https://stackoverflow.com/questions/8515760/make-mediacontroller-show-without-hide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!