Android - streaming internet radio

I plan to make an Android app for one local radio station. I need to make an online broadcast of the radio program. Can you provide some starting point for this, some kind of tutorial or something like that.

+4
source share
1 answer

Source URL: http://shoutcast2.omroep.nl:8104/

To initialize MediaPlayer, you need a few lines of code. There you go:

MediaPlayer player = new MediaPlayer(); player.setDataSource("http://shoutcast2.omroep.nl:8104/"); 

Now that the MediaPlayer is initialized, you are ready to start streaming. Good, really. You will need to issue the MediaPlayer preparation command. There are two options for this.

1. prepare (): This is a synchronous call that blocks until the MediaPlayer object is in the prepared state. This is normal if you are trying to play local files that will use MediaPlayer for longer, otherwise your main stream will be blocked. prepareAsync (): This is, as the name suggests, an asynchronous call. He returns immediately. But, which obviously does not mean that MediaPlayer is prepared yet. You still have to wait until it enters the prepared state, but since this method will not block your main thread, you can use this method when trying to transfer any content from another place. You will receive a callback when MediaPlayer is ready via the onPrepared (MediaPlayer mp) method, and then playback starts. So, for our example, the best choice would be:

2. player.prepareAsync (); You need to connect the listener to MediaPlayer to receive a callback when it is ready. This is the code for this.

 player.setOnPreparedListener(new OnPreparedListener(){ public void onPrepared(MediaPlayer mp) { player.start(); } }); 
+11
source

Source: https://habr.com/ru/post/1391440/


All Articles