Update MediaPlayer starting position when paused

I am broadcasting live audio and want to be able to pause the media player and then start from the current current position. By default, Pause () and Start () only start from where it was stopped. Any ideas on how to update your current position to start () instantly?

+8
android android-mediaplayer
source share
2 answers

Have you tried calling seekTo ()?

You can keep it updated by calling seekTo () every one and a half seconds using TimerTask , but I don't know how I feel about it.

EDIT: If you call seekTo () every 500 milliseconds to continue moving forward, you must call it the current ell since the last call (500 milliseconds in this case). But then again I do not know, this is the best approach. Another way is to create an OnSeekCompleteListener that will transform the new seekTo (currentPosition + timeEllapsed). In this case, you need to calculate timeEllapsed as follows: currentSystemTime - systemTimeOnLastCall

From http://developer.android.com/reference/android/media/MediaPlayer.html :

The playback position can be adjusted by calling seekTo (int).

Although the asynchronous seekTo (int) call returns to the right, the actual search operation may take some time, especially for streaming audio / video. When the actual search operation completes, the player’s internal engine calls the user supplied by OnSeekComplete.onSeekComplete () if OnSeekCompleteListener is registered in advance through setOnSeekCompleteListener (OnSeekCompleteListener).

Note that seekTo (int) can also be called in other states, such as a ready, pause, and play state.

In addition, the actual current playback position can be obtained by calling getCurrentPosition (), which is useful for applications such as a music player that need to track playback progress.

+6
source share

You call MediaPlayer.getCurrentPosition when you pause your MediaPlayer and call MediaPlayer.seekTo to get back a place in MediaPlayer when it restarts.

+1
source share

All Articles