views:

6261

answers:

8

Hi,

I've been trying to stream mp3's over http using Android's built in MediaPlayer class. The documentation would suggest to me that this should be as easy as :

MediaPlayer mp = new MediaPlayer();
mp.setDataSource(URL_OF_FILE);
mp.prepare();
mp.start();

However I am getting the following repeatedly. I have tried different URLs as well. Please don't tell me that streaming doesn't work on mp3's.

E/PlayerDriver(   31): Command PLAYER_SET_DATA_SOURCE completed with an error or info PVMFErrNotSupported
W/PlayerDriver(   31): PVMFInfoErrorHandlingComplete
E/MediaPlayer(  198): error (1, -4)
E/MediaPlayer(  198): start called in state 0
E/MediaPlayer(  198): error (-38, 0)
E/MediaPlayer(  198): Error (1,-4)
E/MediaPlayer(  198): Error (-38,0)

Any help much appreciated, thanks S

+3  A: 

Check out this site: Custom Audio Streaming with MediaPlayer

Hope it helps.

GrkEngineer
Thanks I've read that tutorial, but I would like to know if the SDK works as advertised in the docs. ie, should I be able to play a sound file from a URL using progressive download without having to go so low level as to buffer the stream myself.Thanks
Pandalover
yes it does progressive download. I checked it n it works fine.
Bohemian
Could I ask for more detail please as I have checked directly with Google and there is a definitie issue here.Are you using a device, or the simulator to do this, and what kind of url and file are you using. It definitely doesn't work on a European HTC Hero or any of the simulators current simulators on a Mac for the mp4 url I am using currently.
Pandalover
This is pasted from my correspondence with a Google Developer Advocate on the matter...There's definitely a problem there - I'm not 100% sure of the cause. The underlying error seems to be that the stream format is unsupported, but that doesn't sound quite right to me. I've pased this on the the engineer who handles the multimedia parts of the Android Framework to see if he has any insight. I will mention that for streaming video it needs to be wrapped within a 3gp file, I didn't think that was the case for audio but it's possible...
Pandalover
+1  A: 

I've had the same error as you have and it turned out that there was nothing wrong with the code. The problem was that the webserver was sending the wrong Content-Type header.

Try wireshark or something similar to see what content-type the webserver is sending.

doep
in this case what is the correct content type?
Lyubomyr Dutko
for mp3-files it should be Content-Type: audio/mpegThat solved my problem :)
doep
A: 

No call mp.start with an OnPreparedListener to avoid the zero state i the log..

Fred Grott
A: 

Pandalover, did google ever tell you anything concrete about those errors? I am getting some of the same errors from MediaPlayer when trying to stream audio, and cannot find definitions for them anywhere. Any help is appreciated.

JoeyD
A: 

I am using "http://www.pocketjourney.com/downloads/pj/tutorials/audio.mp3" url to listen to audio and it works fine but when I work with live streaming like online radio , media player show same error mentioned in the first post. for example http://www.radio.net/rad/radio.asx is the URL

Nrana
A: 

I am getting the same error when i try to stream the audio from a radio. I am looking for a example to work with streaming online radio.

averm
A: 

Android MediaPlayer doesn't support streaming of MP3 natively until 2.2. In older versions of the OS it appears to only stream 3GP natively. You can try the pocketjourney code, although it's old (there's a new version here) and I had trouble making it sticky — it would stutter whenever it refilled the buffer.

The NPR News app for Android is open source and uses a local proxy server to handle MP3 streaming in versions of the OS before 2.2. You can see the relevant code in lines 199-216 (r94) here: http://code.google.com/p/npr-android-app/source/browse/trunk/Npr/src/org/npr/android/news/PlaybackService.java

And this is the StreamProxy class: http://code.google.com/p/npr-android-app/source/browse/trunk/Npr/src/org/npr/android/news/StreamProxy.java

The NPR app is also still getting the "error (-38, 0)" sometimes while streaming. This may be a threading issue or a network change issue. Check the issue tracker for updates.

jwadsack
Are you absolutely sure about this? My understanding is that it was to do with the mime type. Could you check whether t works with the right MIME type pre 2.1? I am working on something else right now and couldn't check for a while.
Pandalover
According to the 2.2 release notes (http://developer.android.com/sdk/android-2.2-highlights.html), it includes a "New media framework (Stagefright) that supports local file playback and HTTP progressive streaming". In all my testing I was unable to get a 2.1 device to stream from a shoutcast server directly.I believe that the issue is that shoutcast servers return a protocol of ICY/1.1 rather than HTTP/1.1 and the media player trips up on this as it doesn't know how to respond to that content.
jwadsack
A: 

Now,I alse find the problem that I cann't play live audio with adroid media player. Can some one give a solution?

This not an answer to the question.
Jay Askren