如何使用Android媒体播放器以asx格式播放无线电流

时间:2013-05-13 00:52:37

标签: android streaming radio

我想播放这个流媒体网址:

http://www.mediacorpradio.sg/radioliveplayer/asx/class95/fm950.asx

我尝试了什么:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
            ...


    // player
    player = new MediaPlayer();
    player.setAudioStreamType(AudioManager.STREAM_MUSIC);
    player.setOnPreparedListener(new OnPreparedListener() {
        public void onPrepared(MediaPlayer mp) {
            mp.start();
            button.setImageResource(R.drawable.pause);
        }
    });
    try {
        player.setDataSource(radio_url);
    } catch (Exception e) {
        toast("Unable to play this radio. Please email us if you see this constantly.");
        return;
    }

    player.prepareAsync();

}

private void toggleState(){
    if (player.isPlaying()) {
        player.pause();
        button.setImageResource(R.drawable.play);
    }else{
        player.prepareAsync();
    }
}

@Override
public void onDestroy() {
    super.onDestroy();
    player.release();
}

我得到的错误:(1,-1004)

0 个答案:

没有答案