Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
The
seekTo()
method works well when
mediaPlayer
is playing. If
mediaPlayer
is paused, when I seek to a position and call
start()
, it just start playing where it paused.
My code is as following, in the logcat, I can see it seeking.
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
if(player == null || player.mediaPlayer == null){
return;
Log.e("player status", "status is " + PlayerStatusCache.playerStatus);
if(durationProgress < player.mediaPlayer.getDuration()){
player.mediaPlayer.seekTo(durationProgress);
Log.e("player", "seeking");
} else {
player.mediaPlayer.seekTo(player.mediaPlayer.getDuration() - 1000);
For some reasons on some devices : SystemClock.sleep(200)
is necessary because onSeekComplete(MediaPlayer arg0)
is called too soon by the player BEFORE seekTo is really completed.
mMediaPlayer.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
@Override
public void onSeekComplete(MediaPlayer arg0) {
Log.d(TAG, "onSeekComplete() current pos : " + arg0.getCurrentPosition());
SystemClock.sleep(200);
mMediaPlayer.start();
try {
mMediaPlayer.seekTo(mCurrentPos);
} catch (IllegalStateException e){
Log.d(TAG, e.getLocalizedMessage(), e);
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.