SeekTo initially in Android’s Mediaplayer makes mediaplayer not work

Uncategorized
This is the method where I create my Mediaplayer and set it’s source, but directly after I call seekTo it does’t play anymore (If I give it some time-depends on the audio, it worksm–> Conclusion after debug).

public void makeAudio(boolean isInit){
try{
if(!isInit){
mediaPlayer = new MediaPlayer();
}
soundSource = episode.getAudio();
mediaPlayer.setDataSource(soundSource);
mediaPlayer.prepareAsync();

mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@override
public void onPrepared(MediaPlayer mp) {
soundLength = mediaPlayer.getDuration();
seekBar.setMax(soundLength/1000);
mediaPlayer.seekTo(progress);//the problem I guess
}
});

}catch (Exception e){
e.printStackTrace();
}
}
It shows me this error message:

E/MediaPlayerNative: Attempt to perform seekTo in wrong state: mPlayer=0x706c23ebc0, mCurrentState=0
I would like to have any suggestion about this, because I want to make my mediaplayer go to the progress value(I get it from my intent).

Sharing is caring!

Leave a Reply