Android Socket Issue on Samsung Galaxy S4 (SGS4)

We recently received a message about the lack of sound in our Android applications on the Samsung Galaxy S4. The app works great on other devices.

Audio is transmitted using MediaPlayer. It is saved locally using the Android Socket method.

A warning in Logcat is caused by:

try { byte[] buffer = httpString.toString().getBytes(); int readBytes = -1; Log.d(LOG_TAG, "writing to client"); client.getOutputStream().write(buffer, 0, buffer.length); // Start streaming content. byte[] buff = new byte[1024 * 64]; while (isRunning && (readBytes = data.read(buff, 0, buff.length)) != -1) { client.getOutputStream().write(buff, 0, readBytes); } } 

The stack trace is as follows:

 D/StreamProxy(3913): downloaded D/StreamProxy(3913): downloading... D/StreamProxy(3913): reading headers D/StreamProxy(3913): headers done HTTP/1.0 200 OK D/StreamProxy(3913): Content-Type: audio/mpeg D/StreamProxy(3913): D/StreamProxy(3913): writing to client W/StreamProxy(3913): Broken pipe. W/StreamProxy(3913): java.net.SocketException: sendto failed: EPIPE (Broken pipe) W/StreamProxy(3913): at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:506) W/StreamProxy(3913): at libcore.io.IoBridge.sendto(IoBridge.java:475) W/StreamProxy(3913): at java.net.PlainSocketImpl.write(PlainSocketImpl.java:507) W/StreamProxy(3913): at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46) W/StreamProxy(3913): at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269) W/StreamProxy(3913): at com.gm.mobile.util.StreamProxy.processRequest(StreamProxy.java:234) W/StreamProxy(3913): at com.gm.mobile.util.StreamProxy.run(StreamProxy.java:123) W/StreamProxy(3913): at java.lang.Thread.run(Thread.java:856) W/StreamProxy(3913): Caused by: libcore.io.ErrnoException: sendto failed: EPIPE (Broken pipe) W/StreamProxy(3913): at libcore.io.Posix.sendtoBytes(Native Method) W/StreamProxy(3913): at libcore.io.Posix.sendto(Posix.java:151) W/StreamProxy(3913): at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177) W/StreamProxy(3913): at libcore.io.IoBridge.sendto(IoBridge.java:473) W/StreamProxy(3913): ... 6 more E/(3913): client closing D/StreamProxy(3913): Proxy interrupted. Shutting down. 

The stream plays when I comment on the proxy code, however it starts playing for a second and then starts buffering for 2-3 seconds before resuming.

Any decisions will be taken into account.

I found similar problems, but they were not resolved:

  • Android: Socket - java.net.SocketException: sendto failed: EPIPE (Broken pipe)
  • Media Player socket exception in Samsung Grand
+8
android samsung-mobile proxy android-mediaplayer
source share
2 answers

I finally figured out what caused it. As expected, the media player made range requests, trying to find id3 information. On other phones, simply setting the header status bar to HTTP/1.0 206 OK will prevent the media player from making such range requests. However, for some odd reason, this is not the case on S4 (thanks to Samsung!).

So, to fix this, you just need to handle these range requests. In my case, I only called socket.accept() once. I changed this to execute in a loop, and isRunning is true in my run() function. Thus, when a new request is executed, it is handled appropriately. A shortened version of my code looks like this:

 public void run() { while (isRunning) { client = socket.accept(); HttpResponse cloudResponse = startCloudRequest(); sendDataToMediaPlayer(cloudResponse); } } 

Hope this helps.

+4
source share

A broken pipe usually occurs when the other side has closed the connection with you. Make sure that you have proxied the headers correctly and then insert two new lines before throwing them into the body. Something that you feed on the other end will most likely cause a socket proximity ... Does this only happen on S4? Are you submitting the length of the content?

0
source share

All Articles