title: Why does it take so long for Android's MediaPlayer to prepare some live streams for playback?
body: <p>I am finding big differences in the time it takes the Android MediaPlayer to prepare for live stream playback with different streams.</p>
  
  <p><strong>The hard data</strong></p>
  
  <p>I added logging between prepareAsync() and the onPrepared(MediaPlayer mp) callback and tested several streams a few times each.  The times for each stream were very consistent (+/- one second), and here are the results:</p>
  
  <ol>
  <li>MPR news stream: 27 seconds (http://newsstream1.publicradio.org:80/)</li>
  <li>MPR classical music stream: 15 seconds (http://classicalstream1.publicradio.org:80/)</li>
  <li>MPR The Current stream: 7 seconds (http://currentstream1.publicradio.org:80/)</li>
  <li>PRI stream: 52 seconds (http://pri-ice.streamguys.biz/pri1)</li>
  </ol>
  
  <p>The tests were performed on a Nexus S with Android 2.3.4 on a 3G connection (~1100 Kbps).</p>
  
  <p>Playing non-streaming MP3 audio files is not an issue.</p>
  
  <p>Here are snippets of how I am playing the streams:</p>
  
  <p>Prepare MediaPlayer:</p>
  
  <pre><code>...
  mediaPlayer.setDataSource(playUrl);
  mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  mediaPlayer.prepareAsync();
  ...
  </code></pre>
  
  <p>Then in onPrepared(MediaPlayer mp):</p>
  
  <pre><code>mediaPlayer.start();
  </code></pre>
  
  <p>Why does it take so long to prepare some streams but not others?  The above data seems to suggest that it <em>might</em> be based on the <em>amount</em> of data that has been buffered and not the <em>duration</em> of the buffered audio content.  Could this really be?</p>
  
  <p><strong>Update:</strong> I have tested live streaming on physical devices with Android 1.6, 2.2 and 2.3.4 and emulators with 1.6, 2.1, 2.2, 2.3.1 and 2.3.3.  I am only seeing the long delay on 2.3.3 and 2.3.4.  The older versions start playback within 5 seconds.</p>