OSDN Git Service

Update the Music app to use the remote control focus API.
authorJean-Michel Trivi <jmtrivi@google.com>
Wed, 17 Mar 2010 18:46:58 +0000 (11:46 -0700)
committerJean-Michel Trivi <jmtrivi@google.com>
Mon, 22 Mar 2010 23:45:26 +0000 (16:45 -0700)
Request media button events whenever the user has started the
playback of audio content.

Change-Id: I61cb54b2f9b0c9ad3a0728f4110f37497026b27c

src/com/android/music/MediaButtonIntentReceiver.java
src/com/android/music/MediaPlaybackService.java

index 3a9fcf4..6b5a9d8 100644 (file)
@@ -130,7 +130,9 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
                     mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT);
                     mDown = false;
                 }
-                abortBroadcast();
+                if (isOrderedBroadcast()) {
+                    abortBroadcast();
+                }
             }
         }
     }
index 2ea6a22..2413092 100644 (file)
@@ -20,6 +20,7 @@ import android.app.Notification;
 import android.app.PendingIntent;
 import android.app.Service;
 import android.appwidget.AppWidgetManager;
+import android.content.ComponentName;
 import android.content.ContentResolver;
 import android.content.ContentUris;
 import android.content.ContentValues;
@@ -307,6 +308,8 @@ public class MediaPlaybackService extends Service {
 
         mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
         mAudioManager.registerAudioFocusListener(mAudioFocusListener);
+        mAudioManager.registerMediaButtonEventReceiver(new ComponentName(getPackageName(),
+                MediaButtonIntentReceiver.class.getName()));
         
         mPreferences = getSharedPreferences("Music", MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE);
         mCardId = MusicUtils.getCardId(this);
@@ -1081,6 +1084,8 @@ public class MediaPlaybackService extends Service {
     public void play() {
         mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC,
                 AudioManager.AUDIOFOCUS_GAIN);
+        mAudioManager.registerMediaButtonEventReceiver(new ComponentName(this.getPackageName(),
+                MediaButtonIntentReceiver.class.getName()));
 
         if (mPlayer.isInitialized()) {
             // if we are at the end of the song, go to the next song first