title: Android Socket Issue on Samsung Galaxy S4 (SGS4)
body: <p>We have recently been receiving reports of audio not playing in our Android apps, on the Samsung Galaxy S4. The app is fine on other devices.</p>
  
  <p>The audio is streamed using the MediaPlayer. It is saved locally using the Android Socket method.</p>
  
  <p>The warning in the Logcat is caused by:</p>
  
  <pre><code>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 &amp;&amp; (readBytes = data.read(buff, 0, buff.length)) != -1) {
          client.getOutputStream().write(buff, 0, readBytes);
      }
  }
  </code></pre>
  
  <p>The stack trace is as follows:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>The stream plays when I comment out the proxy code, however, it starts playing for a second, then starts buffering for 2-3 seconds, before resuming.</p>
  
  <p>Any solutions would be greatly accepted.</p>
  
  <p>I have found similar issues, but they have not been solved:  </p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/14622700/android-socket-java-net-socketexception-sendto-failed-epipe-broken-pipe">Android : Socket - java.net.SocketException: sendto failed: EPIPE (Broken pipe)</a>  </li>
  <li><a href="https://stackoverflow.com/questions/16075082/media-player-socket-exception-in-samsung-grand">Media Player socket exception in Samsung Grand</a></li>
  </ul>