VideoView 播放的 Acitivity LifeCycle 问题

发布于 2024-08-25 16:37:56 字数 1352 浏览 2 评论 0原文

大家好,我遇到了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

香草可樂 2024-09-01 16:37:56

好的,看起来该行为与 Activity 生命周期以及 VideoViewActivity 在清单中设置为横向这一事实有关。 添加

android:configChanges="keyboardHidden|orientation" 

为该活动
似乎解决了这个问题,然后你只让设备进入睡眠状态,与之前调用的 onPause() 相比 - 所有生命周期方法都被执行。
我会做更多测试以确保它已修复......

OK, Looks like the behavior is related to activity lifecycle and the fact that VideoViewActivity is set to landscape in the manifest. Adding

android:configChanges="keyboardHidden|orientation" 

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文