Android back button and MediaController

后端 未结 4 1863
别那么骄傲
别那么骄傲 2020-12-03 03:09

I know how to take control of the back button. I have a VideoView embedded in a FrameLayout. My question is when the video pops up, the video contr

4条回答
  •  长情又很酷
    2020-12-03 03:15

    The previous solutions no longer work with Android Pie +, you must instead :

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            mediaController.addOnUnhandledKeyEventListener((v, event) -> {
                //Handle BACK button
                if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP)
                {
                    mediaController.hide(); //Hide mediaController,according to your needs, you can also called here onBackPressed() or finish() 
                }
                return true;
            });
        }
    

提交回复
热议问题