I want to play the sound on Android 2.3 , with the SHOUTcast radio broadcast, without any lotions, with one click on the button. All attempts are vain. Perhaps some special codec library is needed? Share any advice please. Thank you in advance.
2 answers
MediaPlayer mp = new MediaPlayer(); mp.setDataSource("http://ссылка на радио"); mp.prepare(); mp.start();
You can wrap the whole thing in service
and play in the background.
|
try { String url = "http://..."; // Твой URL MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setDataSource(url); mediaPlayer.prepare(); mediaPlayer.start(); } catch (IOException e) { e.printStackTrace(); }
Do not forget to take permishn for the Internet.
|