Problem with back button in VideoView

后端 未结 5 517
感动是毒
感动是毒 2021-01-05 08:03

I am having difficulty getting the back button to actually finish my activity when pressed. I am running a very simple videoview, using a progressdialog to show loading dial

5条回答
  •  一生所求
    2021-01-05 08:46

    You can simply write: (No need to create new class for MediaController)

    mVideoView.setMediaController(new MediaController(this){
            public boolean dispatchKeyEvent(KeyEvent event)
            {
                if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP)
                    ((Activity) getContext()).finish();
    
                return super.dispatchKeyEvent(event);
            }
        });
    

提交回复
热议问题