The docs for
Prepares the player for playback, asynchronously. After setting the
datasource and the display surface, you need to either call prepare()
or prepareAsync(). For streams, you should call prepareAsync(),
which returns immediately, rather than blocking until enough data
has been buffered.
mPlayer = new MediaPlayer();
Doing complex operations in the UI thread is a bad practice. It can block your UI for a long time and Android may kill your app. In this case, the prepare() method can take a lot of time due to decoding and fetching data.
You should call the prepareAsync() method while listening the OnPrepared event. When the event is triggered you should notify your UI and start the player.
mPlayer = new MediaPlayer(); mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mPlayer.setDataSource(STREAM_URL); mplayer.setOnPreparedListener(/*your listener here*/) mPlayer.prepareAsync();