Make MediaController show without hiding

I am trying to use MediaController to play music. I want the MediaController to appear until the back button is pressed. Now I will try to make the code below:

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 this is another problem while the MediaController is displayed. When the MediaController appears, tap the screen, the MediaController will hide. I am also already trying to make the code below:

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

But that did not work. The string did not appear in Logcat. Anyone have an idea to do this?

+4
source share
2 answers

Cancel this method also inside the media controller

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

If you want to save the hide () method, but the controller should not disappear every time the control is used:

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

Source: https://habr.com/ru/post/1386453/


All Articles