I'm using VideoView with MediaController. I'm fighting with back-press bug, which is common and on SO we can find a lot of topics about that:
Android back button and MediaController
Back button won't work when VideoView is playing video
First Back button press not caught when playing a video android
Problem with back button in VideoView
all of these are suggesting overriding dispatchKeyEvent inside MediaController. But it won't fire on Android Pie... Method works on older OS versions, but on Pie I'm not getting a dispatchKeyEvent or onKeyPressed call anywhere when media controls are visible - Activity (onBackPressed also checked), any View including VideoView (has focus during whole runtime) and MediaController. In fact as long as MediaController is visible on screen the back button isn't working (isn't closing Activity nor hidding MediaController) and I can't figure out "who" consumes that event...
MediaController mp = new MediaController(this) {
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
if (event.getAction() == KeyEvent.ACTION_UP)
onBackPressed();
return true;
}
return super.dispatchKeyEvent(event);
}
};
videoView.setMediaController(mp);
when I remove above code everything works fine, but I need these media controls
someone had a similar problem year ago, without any answer... (note that Pie is younger...)
Android back button not working while playing video in VideoView