I'm trying to create an audio streamer with Android's MediaPlayer. It's just fine if it doesn't work with Android 2.1 or bellow. I need to be able to play the audio from a SHOUTcast stream. Here's 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 play just nothing. I think it may be related to the app permissions. Does anyone know what's going on?
Thanks!
[UPDATE] I'm getting 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.
One of the most important components of the media framework is the MediaPlayer class. An object of this class can fetch, decode, and play both audio and video with minimal setup.
A redesigned media player One of the more obvious upgrades you'll see on Android 13, is a redesigned media player widget. It shows up under Quick Settings and on the lock screen when media is playing.
Sorry for the late response, ran across this while looking for answers to another problem.
If you still need an answer, you're calling start()
while it's still being prepared. PrepareAsync()
returns immediately, unlike prepare()
. The problem with using 'prepare()` with streams is that it will block until it has enough data to start play.
What you want to do is set an OnPreparedListener
, and have the start()
called from there.
The problem is that content type "audio/aacp" streaming is not supported directly . Some decoding library can be sued to play "aacp", please see the solution below:
Freeware Advanced Audio (AAC) Decoder for Android
How to use this library?
For more detail please see this.
Consider legal issues while using it.
- the project http://code.google.com/p/aacplayer-android/ is licensed under GPL, so you can create commercial apps * on top of it, but you need to fullfill the GPL - mainly it means to publish your code as well. * If you use the second project http://code.google.com/p/aacdecoder-android/ , then you do not need to publish your * code (the library is licensed under LGPL).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With