Fix media player decode function. Bug 2317821.

There was a recent change to OpenCORE that broke the MediaPlayer::decode()
function for all OpenCORE supported formats (MP3, AAC, and AMR-NB/WB). The
affect is that SoundPool is unreliable for all of these formats. This patch
changes the logic in the AudioCache object that processes messages from the
media player. The old logic was fragile. This change should make it more
robust against changes.
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index 0a6c365..df673a4 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -1573,12 +1573,14 @@
         uint32_t sampleRate, int channelCount, int format, int bufferCount,
         AudioCallback cb, void *cookie)
 {
+    LOGV("open(%u, %d, %d, %d)", sampleRate, channelCount, format, bufferCount);
     if (cb != NULL) {
         return UNKNOWN_ERROR;  // TODO: implement this.
     }
+    if (mHeap->getHeapID() < 0) {
+        return NO_INIT;
+    }
 
-    LOGV("open(%u, %d, %d, %d)", sampleRate, channelCount, format, bufferCount);
-    if (mHeap->getHeapID() < 0) return NO_INIT;
     mSampleRate = sampleRate;
     mChannelCount = (uint16_t)channelCount;
     mFormat = (uint16_t)format;
@@ -1627,16 +1629,24 @@
     AudioCache* p = static_cast<AudioCache*>(cookie);
 
     // ignore buffering messages
-    if (msg == MEDIA_BUFFERING_UPDATE) return;
-
-    // set error condition
-    if (msg == MEDIA_ERROR) {
+    switch (msg)
+    {
+    case MEDIA_ERROR:
         LOGE("Error %d, %d occurred", ext1, ext2);
         p->mError = ext1;
+        break;
+    case MEDIA_PREPARED:
+        LOGV("prepared");
+        break;
+    case MEDIA_PLAYBACK_COMPLETE:
+        LOGV("playback complete");
+        break;
+    default:
+        LOGV("ignored");
+        return;
     }
 
     // wake up thread
-    LOGV("wakeup thread");
     p->mCommandComplete = true;
     p->mSignal.signal();
 }