VideoView播放视频时,后退按钮不起作用 [英] Back button won't work when VideoView is playing video
问题描述
我的一个Activities
中有一个VideoView
,如果我尝试向后按Button
,则不会带我到上一个Activity
,并且在该窗口中也没有任何错误消息还是猫.
I have a VideoView
in one of my Activities
and if I try to press the back Button
it doesn't take me to the previous Activity
and it doesn't give any error messages in the log cat either.
我尝试覆盖onBackPressed()
方法,并尝试使用Intent
调用上一个Activity
,但是即使后面的Button
也不执行任何操作.
I have tried overriding the onBackPressed()
method and I have tried calling the prev Activity
using an Intent
, but even then the back Button
didn't do anything.
仅当视频正在播放时,甚至在完成播放后,也会出现此问题.后面的Button
唯一的工作时间是在视频开始播放之前.我的VideoView
也设置了MediaController
.
This problem only occurs when the video is playing and even after it is finished playing. The only time the back Button
works is before the video starts playing. My VideoView
also has a MediaController
set to it.
有什么想法吗?
谢谢!
推荐答案
来自CommansWare
From CommansWare
基于源代码,这应该可以工作:
Based on the source code, this should work:
- 扩展MediaController(出于此答案的目的,将其称为 RonnieMediaController)
- 在RonnieMediaController中覆盖dispatchKeyEvent()
- 在链接到超类之前,请检查KeyEvent.KEYCODE_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.
这篇关于VideoView播放视频时,后退按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!