private void initPlayer() throws Exception { streamer = new HttpMediaStreamer(mFileName, mMimeType); Uri uri = streamer.getUri(); mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setOnPreparedListener( new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mediaPlayer.start(); } }); mediaPlayer.setOnCompletionListener( new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { killPlayer(); } }); mediaPlayer.setDataSource(mContext, uri); mediaPlayer.prepareAsync(); }
private void killPlayer() { if (mediaPlayer != null) { mediaPlayer.stop(); mediaPlayer.release(); mediaPlayer = null; } if (streamer != null) { streamer.destroy(); streamer = null; } }