Sometimes MediaPlayer prepareAsyc() doesn't call onPrepared() until POWER pressed
<p>I've been trying to reproduce what my QA team calls the "Random Pausing Bug" for some time.  Today, I reproduced it three times while debugging with logcat on.  It appears intermittently and only in poor network.</p>

<p>The user experiences audio pause, until they go touch their phone (press the power or trackball) and it immediately starts playing again.  This is because I call start in the onPrepared callback, and start is never called in these cases.  This is our most severe bug.</p>

<p>What I Know:</p>

<p>1) This happens intermittently on the Nexus One with 2.2.1 (not sure if it's on other devices)</p>

<p>2) I call prepareAsyc() from a PlaybackService while the device screen is off.  Sometimes, onPrepared() is never called, so my subsequent mediaplayer.start() call is never fired.  I can see with network sniffers and the buffering callback that buffering is happening.</p>

<p>3) If I touch the devices power or trackball to wake it up, onPrepared() is immediately called (already buffered) and my callback starts playback.</p>

<p>Here are logs with time stamps showing the issue three times:</p>

<p>FIRST EXAMPLE (no callback for 20s until I hit power button): </p>

<pre><code>11-10 16:10:55.966 I/AwesomePlayer(   59): calling prefetcher-&gt;prepare()
11-10 16:11:15.511 D/KeyguardViewMediator(   94): wakeWhenReadyLocked(26)
11-10 16:11:15.511 D/KeyguardViewMediator(   94): handleWakeWhenReady(26)
11-10 16:11:15.511 D/KeyguardViewMediator(   94): pokeWakelock(5000)
11-10 16:11:15.511 I/power   (   94): *** set_screen_state 1
11-10 16:11:15.561 D/SurfaceFlinger(   94): Screen about to return, flinger = 0x1fe300
11-10 16:11:15.701 D/AK8973  (   64): Compass Start
11-10 16:11:15.701 D/WifiService(   94): ACTION_SCREEN_ON
11-10 16:11:15.711 I/Prefetcher(   59): [0x602d80] cache below low water mark, filling cache.
11-10 16:11:15.821 I/AwesomePlayer(   59): prefetcher is done preparing
11-10 16:11:15.831 W/MogMediaPlayer.onPreparedListener( 2968): onPrepared, calling notifyPrepared()
</code></pre>

<p>TWO MORE EXAMPLES (the first time 3s before I hit power, the next was 8s):</p>

<pre><code>11-10 16:14:54.649 I/AwesomePlayer(   59): calling prefetcher-&gt;prepare()
11-10 16:14:57.500 D/KeyguardViewMediator(   94): wakeWhenReadyLocked(26)
11-10 16:14:57.500 D/KeyguardViewMediator(   94): handleWakeWhenReady(26)
11-10 16:14:57.500 D/KeyguardViewMediator(   94): pokeWakelock(5000)
11-10 16:14:57.500 I/power   (   94): *** set_screen_state 1
11-10 16:14:57.560 D/SurfaceFlinger(   94): Screen about to return, flinger = 0x1fe300
11-10 16:14:57.580 D/WifiStateTracker(   94): Reset connections and stopping DHCP
11-10 16:14:57.580 D/WifiService(   94): ACTION_SCREEN_ON
11-10 16:14:57.670 I/Prefetcher(   59): [0xa990] cache below low water mark, filling cache.
11-10 16:14:57.700 D/AK8973  (   64): Compass Start
11-10 16:14:57.800 I/AwesomePlayer(   59): prefetcher is done preparing
11-10 16:14:57.800 W/MogMediaPlayer.onPreparedListener( 2968): onPrepared, calling notifyPrepared()



11-10 16:39:03.608 I/AwesomePlayer(   59): calling prefetcher-&gt;prepare()
11-10 16:39:11.506 D/KeyguardViewMediator(   94): wakeWhenReadyLocked(26)
11-10 16:39:11.506 D/KeyguardViewMediator(   94): handleWakeWhenReady(26)
11-10 16:39:11.506 D/KeyguardViewMediator(   94): pokeWakelock(5000)
11-10 16:39:11.506 I/power   (   94): *** set_screen_state 1
11-10 16:39:11.566 D/SurfaceFlinger(   94): Screen about to return, flinger = 0x1fe300
11-10 16:39:11.586 D/WifiStateTracker(   94): Reset connections and stopping DHCP
11-10 16:39:11.586 D/WifiService(   94): ACTION_SCREEN_ON
11-10 16:39:11.716 D/AK8973  (   64): Compass Start
11-10 16:39:11.766 I/Prefetcher(   59): [0x59ac18] cache below low water mark, filling cache.
11-10 16:39:11.856 I/AwesomePlayer(   59): prefetcher is done preparing
11-10 16:39:11.946 W/MogMediaPlayer.onPreparedListener( 2968): onPrepared, calling notifyPrepared()
</code></pre>

<p>Does anyone know anything about this bug or how to work around it?</p>

<p>Thanks in advance,
Ben</p>
