示例#1
0
  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();
  }
示例#2
0
  private void killPlayer() {
    if (mediaPlayer != null) {
      mediaPlayer.stop();
      mediaPlayer.release();
      mediaPlayer = null;
    }

    if (streamer != null) {
      streamer.destroy();
      streamer = null;
    }
  }