VideoView 播放的 Acitivity LifeCycle 问题
大家好,我遇到了 VideoView
的另一个问题。 然后视频正在播放,我使用硬按钮让设备进入睡眠状态,调用 onPause()
。但接下来是:
03-17 11:26:33.779: WARN/ActivityManager(884): Activity pause timeout for HistoryRecord{4359f620 com.package/com.package.VideoViewActivity}
然后我再次使用 onStart()
/onResume()
,视频开始播放。我尝试在 onStart()
/onStop()
周围移动代码 - 似乎没有什么区别。
示例代码:
public class VideoViewActivity extends Activity {
private String path = "";
private VideoView mVideoView;
private static final String MEDIA_URL = "media_url";
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.videoview);
mVideoView = (VideoView)findViewById(R.id.surface_view);
path = getIntent().getStringExtra(MEDIA_URL);
}
@Override
public void onResume() {
super.onResume();
mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.start();
}
@Override
public void onPause() {
super.onPause();
mVideoView.stopPlayback();
mVideoView.setMediaController(null);
}
}
为什么会发生这种情况?我该如何阻止呢?
这并不是最好的体验,而是让设备进入睡眠状态并开始播放视频
Hi all i've ran into another problems with VideoView
.
Then video is playing, and I put device asleep, using hard button, onPause()
is called. But it followed by:
03-17 11:26:33.779: WARN/ActivityManager(884): Activity pause timeout for HistoryRecord{4359f620 com.package/com.package.VideoViewActivity}
And then i have onStart()
/onResume()
again and Video starts playing. I've try to move code around onStart()
/onStop()
- doesn't seems to make difference.
sample code :
public class VideoViewActivity extends Activity {
private String path = "";
private VideoView mVideoView;
private static final String MEDIA_URL = "media_url";
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.videoview);
mVideoView = (VideoView)findViewById(R.id.surface_view);
path = getIntent().getStringExtra(MEDIA_URL);
}
@Override
public void onResume() {
super.onResume();
mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.start();
}
@Override
public void onPause() {
super.onPause();
mVideoView.stopPlayback();
mVideoView.setMediaController(null);
}
}
Why is it happening? And how do I stop that?
It's not a greatest experience than you put your device to sleep and it starts playing video
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,看起来该行为与 Activity 生命周期以及 VideoViewActivity 在清单中设置为横向这一事实有关。 添加
为该活动
似乎解决了这个问题,然后你只让设备进入睡眠状态,与之前调用的 onPause() 相比 - 所有生命周期方法都被执行。
我会做更多测试以确保它已修复......
OK, Looks like the behavior is related to activity lifecycle and the fact that VideoViewActivity is set to landscape in the manifest. Adding
for that activity
seems to fix the problem and then you put device to sleep only onPause() called vs before - all lifecycle methods were executed.
I'll do more testing to make sure it fixed...