You need to call mediaPlayer.start()
in the onPrepared
method by using a listener.
You are getting this error because you are calling mediaPlayer.start()
before it has reached the prepared state.
Here is how you can do it :
mp.setDataSource(url);
mp.setOnPreparedListener(this);
mp.prepareAsync();
public void onPrepared(MediaPlayer player) {
player.start();
}