Problems when restarting MediaPlayer upon screen rotation

648 views
Skip to first unread message

// C

unread,
Feb 11, 2010, 4:56:22 AM2/11/10
to android-platform, martin....@stericsson.com
Hello !
I am currently writing an application where I want to stream video. I
want to be able to continue watching the video after a change in
screen orientation but I am having trouble with player automatic
playback restart after the change.
Upon rotate the activity and MediaPlayer is torn down.
While the session is torn down I store the current playtime:
@Override
public Object onRetainNonConfigurationInstance() {
return( mediaPlayer.getCurrentPosition() );
}

Upon creation of the new Activity when rotation is completed I load
the current playtime by calling:

playTime=((Integer)getLastNonConfigurationInstance()).intValue();

Now I want to restart the MediaPlayer automatically, playing at the
latest stored position, without having to press my "play" button. The
problem I have is that I do not know how to figure out when the
Activity is finished and when it is legal to call
MediaPlayer.start();


I have tried to override the onResume() method and calling start
there, but this fails with an exception indicating that
MediaPlayer.start(); is called in the wrong state.
The same error comes if I try to start in onCreate() and onStart(). :
ERROR/MediaPlayer(10655): start called in state 1

Can anyone help me out a bit here so I will be able to restore my
player automatically?

Message has been deleted

sandeep

unread,
Feb 21, 2011, 1:34:14 AM2/21/11
to android-...@googlegroups.com, martin....@stericsson.com
Start has to be called in or after onResume()  and the surface is created (if u are playing video, This can be done using SurfaceHolder.Callback interface)..

And also make sure that u call prepare() mediaplayer before calling start().


Reply all
Reply to author
Forward
0 new messages