从另一个 Activity 返回后,VideoView 上的视频播放消失

发布于 2024-09-04 22:09:06 字数 827 浏览 3 评论 0原文

我有两个活动:一个活动将 VideoView 附加到 MediaPlayer,第二个活动。
我开始在第一个 Activity 中观看视频,然后在播放期间启动第二个 Activity。
返回第一个活动后,我可以听到声音,但看不到图像。

我的视频布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    <VideoView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_weight="1"
            android:id="@+id/videoView" android:layout_gravity="center" />  
    <ListView android:layout_width="fill_parent" android:layout_height="125dp"
            android:id="@+id/ListView" />
</LinearLayout>

您对视频不显示的原因有什么想法吗?

I have two Activities: one with VideoView attached to MediaPlayer and the second one.
I start watching a video in the first Activity, then during playback I start second Activity.
After going back to first Activity I can hear sound but see no picture.

My Video Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    <VideoView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_weight="1"
            android:id="@+id/videoView" android:layout_gravity="center" />  
    <ListView android:layout_width="fill_parent" android:layout_height="125dp"
            android:id="@+id/ListView" />
</LinearLayout>

Do you have any ideas why video doesn't appear?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

凉城凉梦凉人心 2024-09-11 22:09:06

可能与Activity的生命周期有关。您是否在 onCreate() 方法中开始播放视频?如果是这样,请尝试将其移至 onResume(),当活动发送到后台但又返回时,该方法会被调用。 onCreate() 仅在首次创建时被调用一次。

Might be related to the Activity life cycle. Do you start playing your video in the onCreate() method? If so, try to move it to onResume(), which gets called when an activity is sent to the background but then brought back again. onCreate() only gets called once, when it's first created.

画中仙 2024-09-11 22:09:06

最后,我得到了 MediaPlayer ,它在 onStop 方法中被销毁,并在 onResume 方法中重新创建。

这种方法的主要缺点是,改变方向后,MediaPlayer 必须再次缓冲视频。

我认为主要原因是对 MediaPlayer 的引用丢失了。如果不参考 MediaPlayer,我无法再次将 SurfaceView 设置为视频显示。

Finally I've ended up with MediaPlayer which is destroyed in onStop method and recreated in onResume method.

Main drawback of this approach is that after changing orientation MediaPlayer has to buffer video again.

I think that the main reason was that reference to MediaPlayer was lost. Without reference to MediaPlayer I couldn't set SurfaceView again, as a Video display.

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