Android playing live radio stream?
Can anyone please suggest me how to play live radio stream url in and开发者_运维技巧roid. Someone who has experience in playing live radio url in android.
Thanks
try
{
MediaPlayer media = new MediaPlayer();
media.setAudioStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
media.setDataSource("http://indiespectrum.com:9000");
media.prepare();
media.start();
}
catch(Exception e)
{
//Getting Exception
}
public void startRadio(String streamUrl) {
MediaPlayer mPlayer = new MediaPlayer();
mPlayer.setOnErrorListener(
new MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.e(getClass().getName(), "Error in MediaPlayer: (" + what +") with extra (" +extra +")" );
}
});
try {
mPlayer.setDataSource(streamUrl);
mPlayer.prepare();
mPlayer.start();
} catch (IllegalArgumentException e) {
Log.e(getClass().getName(), "IllegalArgumentException");
} catch (IllegalStateException e) {
Log.e(getClass().getName(), "IllegalStateException");
} catch (IOException e) {
Log.e(getClass().getName(), "IOException");
}
}
Quick copy paste ..
精彩评论