VideoView停止时显示恢复活动并重新启动 [英] VideoView stop display when activity resumed and restart

查看:2862
本文介绍了VideoView停止时显示恢复活动并重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VideoView来显示RTSP流媒体视频。下面你可以找到code片段。

I'm using VideoView to display a rtsp streaming video. Below you can find a snippet of the code.

OnCreate() {
    ...
    // Setup video view
    videoView = (VideoView) findViewById(R.id.videoViewStream);
    videoView.setMediaController(new MediaController(this));
    ....
    // Create a button
}

OnButtonClickListener() {
    videoView.setVideoURI(Uri.parse(videoUri));
videoView.requestFocus();
}

我有关于在OnResume和的onPause功能VideoView没有code。

I have no code concerning the VideoView in the OnResume and OnPause functions.

用例的问题是:


  1. 打开应用程序并开始播放视频

  2. 我尽量减少应用程序获取到Android桌面

  3. 使用其他应用程序

  4. 重新打开或重新触发视频应用

  5. 视频不显示和不运行。我必须reclick在VideoView

问题是的话,怎么可能得到视频再次被重新显示?我应该放的start(),stop()或暂停()上的视频?

The issue is then, how is it possible to get the video to be redisplayed again? Should I have to put start(), stop() or pause() the video?

任何帮助是值得欢迎的。

Any help is welcome.

TA

推荐答案

我会建议您保存当前的视频postition(和所有你在重启的情况下需要),并在的onPause停止播放。在您的onDestroy需要释放的MediaPlayer。如果用户返回然后你会得到onResume或的onCreate。在你的onCreate再次初始化球员像第一次。在onResume您创建一个安全检查,如果球员真的inited,如果一切正常开始播放(或等待click事件)。同时检查上次保存的位置可能寻求。

I would recommend you to save current video postition (and all you need in case of restart) and stop playback in onPause. In onDestroy you need to release mediaPlayer. If user returns you will then get onResume or onCreate. In onCreate you init player again like the first time. In onResume you create a safety check if player is really inited and if everything is ok start playback (or wait for click event). Check also last saved position for possible seek.

我就从OnButtonClickListener提取code到单独的方法,如果你想自动启动播放从clickListener或onResume调用该方法。

I would extract code from OnButtonClickListener into separate method and call that method from clickListener or in onResume if you wish to autostart playback.

更新答案:

我做了发布一个错误。它是由VideoView在 stopPlayback 方法完成的(考虑VideoView源$ C ​​$ C上的grep code)。
我不知道你怎么RTSP流服务器的作品,但流,我使用不支持与VideoView的 seekTo 方法寻求服务器。您可以拨打暂停的onPause 启动 onResume 但是从0这将开始流(在我的情况)。所以我不得不创建自定义搜索栏。但是,这是另一个故事了。

I made a mistake with release. It's done by VideoView in stopPlayback method (look into VideoView source code on grepcode). I don't know how your RTSP streaming server works, but streaming server that I use doesn't support seeking with VideoView's seekTo method. You can call pause in onPause and start in onResume but this will start stream from 0 (in my case). So I had to create custom seekbar. But that's another story.

在我实现我打电话暂停的onPause stopPlayback 的onDestroy 。在的onPause 我还保存最后位置。在的onCreate 我只得到视图,设置媒体控制。在 onResume 我检查我是否有关于最后一个位置的任何信息。如果存在,那么我prepare播放器( setVideoPath requestFocus的启动)与参数(寻求),否则不(寻求= 0)。

In my implementation I'm calling pause in onPause and stopPlayback in onDestroy. In onPause I also store last position. In onCreate I only get view and set media controls. In onResume I check if I have any info about last position. If this exist then I prepare player (setVideoPath, requestFocus, start) with that parameter (seek), otherwise without (seek = 0).

这是我的解决办法:)

这篇关于VideoView停止时显示恢复活动并重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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