流式直播音频在安卓与MP



我正在尝试使用setDataSource从互联网流式直播音频,但是当我添加url时,它说这是一个未处理的异常。有什么问题吗?

String daytonPolice = "http://relay.radioreference.com:80/691484064";
MediaPlayer mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setDataSource(daytonPolice); // It will not take the string of my url
mp.prepareAsync();
mp.start();

这个问题是因为你在调用prepareAsync()之后调用start()。您需要设置onPreparedListener:

String daytonPolice = "http://relay.radioreference.com:80/691484064";
MediaPlayer mp = new MediaPlayer();
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.start();
    }
});
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setDataSource(daytonPolice); // It will not take the string of my url
mp.prepareAsync();

相关内容

  • 没有找到相关文章

最新更新