开发者

Video playback on VideoView disappears after going back from another Activity

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 idea开发者_JAVA百科s why video doesn't appear?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜