简体   繁体   中英

streaming live audio in android with MP

i'm trying to stream live audio form the internet using setDataSource, however when I add the url it says it's an unhandled exception.. any ideas whats wrong here?

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();

The issue is because you are calling start() right after calling prepareAsync(). You need to set an 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM