Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Live audio streaming with Android 2.x

Tags:

android

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

  • How come I can play this stream "http://188.138.112.71:9018/" ?
like image 427
midnight Avatar asked Aug 27 '12 11:08

midnight


1 Answers

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);
}
}
}
like image 55
Athul Harikumar Avatar answered Oct 04 '22 20:10

Athul Harikumar