我正在尝试在我的设备 android 2.2 中流式传输一个直播音频文件...我听说这个直播音频文件在 android 2.2 中不起作用。所以,我尝试使用 android emulator 2.3 然后也没有播放歌曲为什么你能告诉我哪里出错了......并且代码如下......
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();
}
});
}
}