Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resume the mediaplayer?

I am using a media player.

I have the option for starting ,stopping and pausing the player. The problem I have is that I cannot find the option to resume the song from the point that it previously was paused..

Any help provide would be really helpful.

like image 673
Prateek Raj Avatar asked Oct 04 '10 12:10

Prateek Raj


2 Answers

Thank you for your attention but I've got it myself

for pausing the Mediaplayer I used:

Mediaplayer.pause(); length=Mediaplayer.getCurrentPosition(); 

and for resuming the player from the position where it stopped lately is done by:

Mediaplayer.seekTo(length); Mediaplayer.start(); 
like image 162
Prateek Raj Avatar answered Sep 19 '22 15:09

Prateek Raj


I think you should go through the documentation found here: http://developer.android.com/reference/android/media/MediaPlayer.html

Some quotes from the docs:

Playback can be paused and stopped, and the current playback position can be adjusted. Playback can be paused via pause(). When the call to pause() returns, the MediaPlayer object enters the Paused state. Note that the transition from the Started state to the Paused state and vice versa happens asynchronously in the player engine. It may take some time before the state is updated in calls to isPlaying(), and it can be a number of seconds in the case of streamed content.

  • Calling start() to resume playback for a paused MediaPlayer object, and the resumed playback position is the same as where it was paused. When the call to start() returns, the paused MediaPlayer object goes back to the Started state.
  • Calling pause() has no effect on a MediaPlayer object that is already in the Paused state.

States explained:

States of MediaPlayer

And quote from the start() method of the MediaPlayer

public void start ()

Starts or resumes playback. If playback had previously been paused, playback will continue from where it was paused. If playback had been stopped, or never started before, playback will start at the beginning.

So to answer your question directly, to resume the paused MediaPlayer instance from the point where it was paused use start() again on that instance.

like image 44
Maciej Pigulski Avatar answered Sep 19 '22 15:09

Maciej Pigulski