3

We are using MediaPlayer to stream mp3 music which is first cached to local file and MediaPlayer is to stream it via localserver. It worked pretty nice (for about 1.5 years on any android > 1.6 devices) till Sony Ericsson Xperia X10 updated to Android 2.3.3. Suddenly and only on that device and with Android 2.3.3 the audio streaming stopped working.

MediaPlayer occasionally rises error (100,0) but mostly it just stack on MediaPlayer.prepareAsync() method. The investigation shows that issue happens because of

“java.net.SocketException: Connection reset by peer” 

which points to the line:

outstream.write(buffer, skipFirst, length); 

which by the way is successfully executed 2 times before Exception

The code is quite complex so its hard for me to provide it here, but I can return with more info if needed.

In some reason MediaPlayer closes connection just at the moment when we start to fill it with content. Also what seems to be quite strange, from time to time (1/20) MediaPlayer succeeds to play music.

Any ideas?

3 Answers 3

2

Make sure your proxy parses the Range HTTP header correctly. Xperia devices send range requests in the form of Range: bytes=10000-20000 instead of the more common Range: bytes=10000-.

I'm not sure if this really is the problem, but it fixed playback on some newer Xperia devices, my guess would be that the MediaPlayer on older devices is very similar.

0

to be able to assist you more I think we need some code snippets and a debug log. Could you arrange that for us, please. Or even better if you could pass me a version (stripped if you like - I do not wish to steal commersial ideas from you) of the APK and then I could test the apk on our other phones.

Johan, Sony Ericsson Developer support

2
  • @Johan - seeing exactly the same issue - what's the best way to contact you?
    – Jan Berkel
    Nov 25, 2011 at 19:20
  • i have been offline for quite some time. Sorry. Try [email protected] Mar 28, 2012 at 8:42
0

When you seek or skip or the connection is lost and MediaPlayer keeps reconnecting to the proxy server, you must send this response with Status 206 after you get the request and range(int) from the client.

String headers += "HTTP/1.1 206 Partial Content\r\n";
headers += "Content-Type: audio/mpeg\r\n";
headers += "Accept-Ranges: bytes\r\n";
headers += "Content-Length: " + (fileSize-range) + "\r\n";
headers += "Content-Range: bytes "+range + "-" + fileSize + "/*\r\n";
headers += "\r\n";

And when you receive a request from MediaPlayer that does not contain Range in the HTTP header , then it is requesting a new stream file, in this case your response header should look like this:

String headers = "HTTP/1.1 200 OK\r\n";
headers += "Content-Type: audio/mpeg\r\n";
headers += "Accept-Ranges: bytes\r\n";
headers += "Content-Length: " + fileSize + "\r\n";
headers += "\r\n";

Enjoy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.