Android的后退按钮和MediaController按钮、Android、MediaController

2023-09-04 23:18:36 作者:凭直觉寻觅

我知道如何利用后退按钮的控制权。我有一个 VideoView 嵌入在的FrameLayout 。我的问题是当视频弹出,视频控件是present几秒钟。点击Back按钮,而他们看到隐藏的视频控件。有没有办法忽略的功能,做下一个动作后面,如果视频控件不可见?

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 controls are present for a few seconds. Hitting the back button while they are visible hides the video controls. Is there a way to ignore that function and do the next back action as if the video controls weren't visible?

我想问的原因是,如果我真的想回去,我必须打的返回按钮两次;一旦隐藏控件和第二实际回去

The reason I ask is if I really do want to go back, I must hit the back button twice; once to hide the controls and second to actually go back

推荐答案

根据源$ C ​​$ C,这应该工作:

Based on the source code, this should work:

扩展的MediaController (对于这个答案的目的,把它叫做 RonnieMediaController ) 覆盖 dispatchKeyEvent() RonnieMediaController 在链接到超,检查 KeyEvent.KEY code_BACK ,并且如果遇到,告诉你的活动完成( ) 使用 RonnieMediaController ,而不是的MediaController 与你的 VideoView Extend MediaController (for the purposes of this answer, call it RonnieMediaController) Override dispatchKeyEvent() in RonnieMediaController Before chaining to the superclass, check for KeyEvent.KEYCODE_BACK, and if that is encountered, tell your activity to finish() Use RonnieMediaController instead of MediaController with your VideoView

就个人而言,我只希望息事宁人,与此更改用户不能使 RonnieMediaController 消失的需求。

Personally, I'd just leave it alone, as with this change your user cannot make a RonnieMediaController disappear on demand.