问题
i am trying to stream an shoutcast audio file in my device android 2.2...i heard that this shoutcast will not work in android 2.2. so, i tried with android emulator 2.3 then also song not playing why could you tell me where i am going wrong...and the code is below...
public class AudioDemo extends Activity {
final String song_uris="http://stream.radiosai.net:8004/";
private MediaPlayer mediaplayer;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Button play = (Button) findViewById(R.id.play);
Button pause = (Button) findViewById(R.id.pause);
Button Previous = (Button) findViewById(R.id.Previous);
Button Next = (Button) findViewById(R.id.Next);
mediaplayer = new MediaPlayer();
mediaplayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
mediaplayer.setDataSource(song_uris);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mediaplayer.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // might take long! (for buffering, etc)
mediaplayer.start();
}
});
}
}
来源:https://stackoverflow.com/questions/8252513/android-streaming-a-shoutcast-audio-file