Audio Stream Using Android MediaPlayer

I am trying to create an audio stream with Android MediaPlayer. This is normal if it does not work with Android 2.1 or lower. I need to be able to play audio from a SHOUTcast stream. Here is my code:

player = new MediaPlayer(); try { player.setDataSource("http://87.230.103.107:8000"); player.prepareAsync(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } player.start(); 

For some reason, this code will only play nothing. I think this may be due to application permissions. Does anyone know what is going on?

Thanks!

[UPDATE] I get the following errors:

 04-25 23:35:15.432: ERROR/MediaPlayer(283): start called in state 4 04-25 23:35:15.432: ERROR/MediaPlayer(283): error (-38, 0) 04-25 23:35:15.602: ERROR/MediaPlayer(283): Error (-38,0) 04-25 23:35:17.542: INFO/AwesomePlayer(33): calling prefetcher->prepare() 04-25 23:35:18.547: INFO/Prefetcher(33): [0x17650] cache below low water mark, filling cache. 04-25 23:35:18.762: INFO/AwesomePlayer(33): prefetcher is done preparing 04-25 23:35:19.769: ERROR/AwesomePlayer(33): Not sending buffering status because duration is unknown. 
+6
source share
3 answers

Sorry for the late reply, stumbled upon this, looking for answers to another problem.

If you still need an answer, you call start() while it is still prepared. PrepareAsync() returns immediately, unlike prepare() . The problem with using 'prepare () `with streams is that it will block until there is enough data to start playback.

What you want to do is set OnPreparedListener and call start() from there.

+5
source

The problem is that streaming audio / aacp content is not directly supported. Some decoding library may be sued to play "aacp", see Decision below:

Freeware Advanced Audio (AAC) Decoder for Android

How to use this library?

See more details.

Consider legal issues when using .

+3
source

1) Avoid using prepare (), use prepareAsyc () instead. (or) put your playback logic in a processed thread or a separate thread. 1) Avoid using player.prepare (); use player.prepareAsync () instead;

(or) save the logic in a separate thread. (you can use the intent service, AsyncTask, etc.)

2) Also try with the static constructor MediaPlayer.create (Uri);

-1
source

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


All Articles