Android Media Player: Start called in state 4 error(-38,0)
You can also use below onPrepared()
method to call start method so that start()
is called after MediaPlayer
is prepared.
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.start();
}
});
Instead of using this preparedSync/prepare
method of MediaPlayer
you can just pass the file path converting into URI to the MediaPlayer.create()
MediaPlayer mediaPlayer = MediaPlayer.create(context, URI.parse("file://"+filePath));
this will prepare it and start playing itself
Or another way is use onPrepareListener()
of MediaPlayer
and then from this on prepared start playing