title: Using php to opening live audio stream on android
body: <p>We have shoutcast/icecast audio streams. I'd like to be able to provide a link such as mobiledroid.php on our web site that will open using default player. I've seen this <a href="http://mobile.shoutcaststreaming.us/metal/" rel="nofollow noreferrer">done on another site</a> so I do know it's possible.</p>
  <p>I assume it uses php headers and streams via the php file as a stream?</p>
  <hr />
  <p>Using Brad's instructions, the android actually gives the option to open with sound player. Nice one.</p>
  <p>It also plays on WMP through PC but not on the android how the above link plays</p>
  <pre><code>header(&quot;Content-type: audio/mpeg&quot;); 
  header(&quot;Transfer-Encoding: chunked&quot;); 
  header(&quot;Connection: close&quot;);
  
  $sock = fsockopen($streamname,$port); //$streamname is the IP
  
  fputs($sock, &quot;GET $path HTTP/1.0\r\n&quot;); //path in my case is /;stream.mp3
  fputs($sock, &quot;Host: $ip\r\n&quot;); 
  fputs($sock, &quot;User-Agent: WinampMPEG/2.8\r\n&quot;); 
  fputs($sock, &quot;Accept: */*\r\n&quot;); 
  fputs($sock, &quot;Icy-MetaData:1\r\n&quot;); 
  fputs($sock, &quot;Connection: close\r\n\r\n&quot;); 
  
  
  fpassthru($sock); 
  
  fclose($sock);
  </code></pre>
  <p>On the android, it says &quot;Sorry, this player does not support this type of audio file&quot;</p>
  <hr />
  <p><strong>Update 2:</strong></p>
  <p>Removing <code>&quot;Transfer-Encoding&quot;</code> will play on android but as usual will take a long time to begin stream with &quot;Preparing&quot; status due to a live stream not having &quot;Content-Length&quot;</p>
  <p><code>header(&quot;Transfer-Encoding: none&quot;);</code> also removed from above code:</p>
  <p>Quoting Brad:</p>
  <blockquote>
  <p>Android 2.3 and later has an issue with Transfer-Encoding set to &quot;none&quot;.  Removing that hard-set header puts the stream back to chunked Transfer-Encoding. This works great for Android 2.3+.  Originally I had disabled chunked encoding as VLC doesn't support it.  It also seems that Android 2.2 and older does not support chunked encoding.</p>
  </blockquote>
  <p>Noting here that although it works on android, most live streams will take an awful amount of time to begin.</p>