midnight
midnight

Reputation: 3412

Live audio streaming with Android 2.x

I need to play a live stream on devices with 2.x and greater versions. This states that it's impossible to play live streams on devices with Android 2.x.

What're my options here ? Especially I'm interested in streaming audio - what format should i pick and in conjunction with which protocol ?

P.S. I've tried Vitamio - don't want to make customers download third party libraries.

UPD

Upvotes: 7

Views: 4741

Answers (2)

Krishnakant Dalal
Krishnakant Dalal

Reputation: 3578

You can use RTSP protocol which is supported by Android native media player.

                    player = new MediaPlayer();
                    player.reset();
                    player.setDataSource(intent.getStringExtra("Path"));
                    player.prepare();
                    player.setOnPreparedListener(new OnPreparedListener() {

                        public void onPrepared(MediaPlayer mp) {
                            player.start();
                        }
                    });

Where path would be your rtsp audio streaming url.

Upvotes: 0

Athul Harikumar
Athul Harikumar

Reputation: 2491

try this example for RTSP streaming (the url should support RTSP) for video change the code to support just audio

public class MultimediaActivity extends Activity {
private static final String RTSP = "rtsp://url here";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.multimedia);


         //***VideoView to video element inside Multimedia.xml file
  VideoView videoView = (VideoView) findViewById(R.id.video);
  Log.v("Video", "***Video to Play:: " + RTSP);
  MediaController mc = new MediaController(this);
  mc.setAnchorView(videoView);
  Uri video = Uri.parse(RTSP);
  videoView.setMediaController(mc);
  videoView.setVideoURI(video);
  videoView.start();

}
}

EDIT:

Live Audio streaming using MediaPlayer in Android Live Audio streaming in android, from 1.6 sdk onwards is become so easy. In setDataSource() API directly pass the url and audio will play without any issues.

The complete code snippet is,

 public class AudioStream extends Activity {

 @Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
String url = "http://www.songblasts.com/songs/hindi/t/three-idiots/01-Aal_Izz_Well-(SongsBlasts.Com).mp3";
 MediaPlayer mp = new MediaPlayer();
try {
 mp.setDataSource(url);
 mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
 mp.prepare();
 mp.start();
} catch (Exception e) {
 Log.i("Exception", "Exception in streaming mediaplayer e = " + e);
}
}
}

Upvotes: 3

Related Questions