VideoView播放视频时,后退按钮不起作用 [英] Back button won't work when VideoView is playing video

查看:319
本文介绍了VideoView播放视频时,后退按钮不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个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:

  1. 扩展MediaController(出于此答案的目的,将其称为 RonnieMediaController)
  2. 在RonnieMediaController中覆盖dispatchKeyEvent()
  3. 在链接到超类之前,请检查KeyEvent.KEYCODE_BACK, 如果遇到这种情况,请告诉您的活动完成()
  4. 在您的计算机上使用RonnieMediaController而不是MediaController VideoView
  1. Extend MediaController (for the purposes of this answer, call it RonnieMediaController)
  2. Override dispatchKeyEvent() in RonnieMediaController
  3. Before chaining to the superclass, check for KeyEvent.KEYCODE_BACK, and if that is encountered, tell your activity to finish()
  4. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆