开发者

Android: Video restarts after orientation changes

I am playing video 开发者_运维知识库in android using VideoView by using different activity other than main activity.

At the time of video is running when i changes the orientation of phone it stops that video then project run from main activity and later video starts from beginning. Even to play video from beginning it taking too much time .

Can i play video immediately and from that position where it stops when orientation changes.

Please suggest me solution.

Thanks in advance.

Nilesh.


Override the following Method in your activity

 @Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    System.out.println("IN onConfigurationChanged()");
}

and add the following property in your manifest file in your activity tag

android:configChanges="orientation"


You can save the current position of the video using VideoView.getCurrentPostion() in onSavedInstance() method. And can start the video using VideoView.seek(pos) and then VideoView.start()

Note: run the seek() and start() methods in a thread.


To help any stumbler

if your android:targetSdkVersion="12" or less

android:configChanges="orientation|keyboardHidden">

if your android:targetSdkVersion="13" or more

android:configChanges="orientation|keyboardHidden|screenSize">

Reference: See Mohit comment on this question Android application restarts on orientation change


add

android:configChanges="orientation"

to your Activity in AndroidManifest.xml.

-thanks to user 'Ashok' source : Rotating phone restarts video on android

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜