Set URL data source for MediaPlayer : MediaPlayer « Media « Android






Set URL data source for MediaPlayer

   

package app.test;

import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;

public class Test extends Activity {

  MediaPlayer mediaPlayer;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mediaPlayer = new MediaPlayer();

    try {
      mediaPlayer.setDataSource("http://yourHost.com/a.mp3");
      mediaPlayer.prepare();
      mediaPlayer.start();
    } catch (IOException e) {
      Log.v("AUDIOHTTPPLAYER", e.getMessage());
    }
  }
}

   
    
    
  








Related examples in the same category

1.Using MediaPlayer to play MP3 file
2.MediaPlayer and Text to Speech
3.Load mp3 file with MediaPlayer and play
4.Call prepare for MediaPlayer before starting
5.Audio MediaPlayer Demo
6.Using MediaPlayer to play Video and Audio
7.extends MediaPlayer
8.MediaPlayer create and start
9.Multi PlayMixer
10.Play movie.m4v file
11.Using Service to play media file