In a project of mine I'm implementing a live radio using an endless stream. I can without any problems use the nativ Android MediaPlayer, also on devices running an old version of Android, since the stream is of type audio/mpeg. I have tested this on an HTC Magic running 1.6 and it works flawless. Even when switching between WLAN and 3G it just buffers up and I only notice a small hiccup and then it keeps on playing as if nothing happened. It also rarely drops connection as I have been listening in on the radio during the work day and also on the way to and from work to make sure it the user experience will be exactly like I want it to. I have repeated the same procedure for other devices like HTC Legend running Android 2.1, HTC Wildfire running 2.2 and Samsung Galaxy Tab running 2.2 with the same results. All devices handle the stream perfectly.
However, and this is where I sort of got stuck, on the HTC Desire running 2.2 I have serious problems getting the stream to play. When using the standard implementation of the MediaPlayer, that is setDataSource(String path), it plays for 10 - 30 seconds then it loses connection even when I have full reception on both WLAN and 3G. I have tried different methods to solve this problem one being using the NPR News project's StreamProxy which actually works pretty good after a few modifications. However the HTC Desire still drops the connections every now and then and at some occasions tries to reconnect 4 - 5 times until it actually succeed in maintaining a stable connection.
The error I'm getting when using the proxy looks as follows
08-08 09:35:17.810: ERROR/AwesomePlayer(67): Not sending buffering status because duration is unknown.
08-08 09:35:19.849: ERROR/HTTPStream(67): recv failed, errno = 11 (Try again)
08-08 09:35:19.849: INFO/HTTPDataSource(67): Retry ... 2 times left
08-08 09:35:19.849: WARN/HTTPStream(67): Calling connect()...
08-08 09:35:19.849: WARN/HTTPStream(67): Returned from connect()...
08-08 09:35:20.739: ERROR/(1576): Broken pipe
08-08 09:35:20.739: ERROR/(1576): java.net.SocketException: Broken pipe
08-08 09:35:20.739: ERROR/(1576): at org.apache.harmony.luni.platform.OSNetworkSystem.writeSocketImpl(Native Method)
08-08 09:35:20.739: ERROR/(1576): at org.apache.harmony.luni.platform.OSNetworkSystem.write(OSNetworkSystem.java:723)
08-08 09:35:20.739: ERROR/(1576): at org.apache.harmony.luni.net.PlainSocketImpl.write(PlainSocketImpl.java:578)
08-08 09:35:20.739: ERROR/(1576): at org.apache.harmony.luni.net.SocketOutputStream.write(SocketOutputStream.java:59)
08-08 09:35:20.739: ERROR/(1576): at org.jmvo.radio.StreamProxy.processRequest(StreamProxy.java:263)
08-08 09:35:20.739: ERROR/(1576): at org.jmvo.radio.StreamProxy.run(StreamProxy.java:138)
08-08 09:35:20.739: ERROR/(1576): at java.lang.Thread.run(Thread.java:1102)
and when using the MediaPlayer directly without the use of the proxy
08-08 09:41:30.799: ERROR/AwesomePlayer(67): Not sending buffering status because duration is unknown.
08-08 09:41:32.849: ERROR/HTTPStream(67): recv failed, errno = 11 (Try again)
08-08 09:41:32.849: INFO/HTTPDataSource(67): Retry ... 2 times left
08-08 09:41:32.849: WARN/HTTPStream(67): Calling connect()...
08-08 09:41:32.870: WARN/HTTPStream(67): Returned from connect()...
08-08 09:41:33.160: INFO/HTTPDataSource(67): retrying connection succeeded.
08-08 09:41:34.839: VERBOSE/CacheingDataSource(67): partial readAt CachingDataSource::readAt(260221, 418):mSource->readAt(page<0xd0ff0>->mOffset 260416, mPageSize 1728)
08-08 09:41:36.839: ERROR/HTTPStream(67): recv failed, errno = 11 (Try again)
08-08 09:41:36.839: INFO/HTTPDataSource(67): Retry ... 1 times left
08-08 09:41:36.839: WARN/HTTPStream(67): Calling connect()...
08-08 09:41:36.859: WARN/HTTPStream(67): Returned from connect()...
08-08 09:41:37.361: INFO/HTTPDataSource(67): retrying connection succeeded.
One more thing. In order for the the StreamProxy from NPR News to work really well I had to modify the following lines
byte[] buff = new byte[1024 * 50];
while (isRunning && (readBytes = data.read(buff, 0, buff.length)) != -1) {
client.getOutputStream().write(buff, 0, readBytes);
}
using it in this way would result in the stream to loose connection every 10 - 30 second. But when I lowered the buffer size to as little as 4 bytes or even one byte it plays quite nicely although when using 3G hiccups occur quite often and it has problems reconnecting.
So my question, does anyone have any ideas of what the deal is with HTC Desires underlying software? I mean, it works perfectly on HTC Wildfire running the same version of the OS. It shouldn't be much differences between the software of the two devices? I've also tested this app on multiple HTC Desires to make sure it wasn't just something wrong with my test device. But on the other devices the same problems occurred just as they did on my test device.
Any ideas?