我尝试使用 MediaController 播放音乐。我希望 MediaController 出现,直到按下“后退”按钮。现在我尝试下面的代码:
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;
}
};
但是当 MediaController 可见时它仍然是一个麻烦。当 MediaController 出现触摸屏时,MediaController 将隐藏。我也已经尝试过以下代码:
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.d("screen","touch");
return true;
}
但它没有用。该字符串未显示在 Logcat 中。有人有想法吗?