Cleaned up media button handling
This commit is contained in:
parent
5d58808d07
commit
3e5ba30a66
2 changed files with 10 additions and 9 deletions
|
|
@ -83,11 +83,17 @@ public class MediaButtonIntentReceiver extends WakefulBroadcastReceiver {
|
|||
@Override
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
if (DEBUG) Log.v(TAG, "Received intent: " + intent);
|
||||
if (handleIntent(context, intent) && isOrderedBroadcast()) {
|
||||
abortBroadcast();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean handleIntent(final Context context, final Intent intent) {
|
||||
final String intentAction = intent.getAction();
|
||||
if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
|
||||
final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
|
||||
if (event == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
final int keycode = event.getKeyCode();
|
||||
|
|
@ -147,14 +153,12 @@ public class MediaButtonIntentReceiver extends WakefulBroadcastReceiver {
|
|||
} else {
|
||||
startService(context, command);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (isOrderedBroadcast()) {
|
||||
abortBroadcast();
|
||||
}
|
||||
releaseWakeLockIfHandlerIdle();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void startService(Context context, String command) {
|
||||
|
|
|
|||
|
|
@ -136,7 +136,6 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
private AudioManager audioManager;
|
||||
@SuppressWarnings("deprecation")
|
||||
private MediaSessionCompat mediaSession;
|
||||
private MediaButtonIntentReceiver mediaButtonIntentReceiver = new MediaButtonIntentReceiver();
|
||||
private PowerManager.WakeLock wakeLock;
|
||||
private PlaybackHandler playerHandler;
|
||||
private final AudioManager.OnAudioFocusChangeListener audioFocusListener = new AudioManager.OnAudioFocusChangeListener() {
|
||||
|
|
@ -268,8 +267,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
|
||||
@Override
|
||||
public boolean onMediaButtonEvent(Intent mediaButtonEvent) {
|
||||
mediaButtonIntentReceiver.onReceive(MusicService.this, mediaButtonEvent);
|
||||
return true;
|
||||
return MediaButtonIntentReceiver.handleIntent(MusicService.this, mediaButtonEvent);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -281,7 +279,6 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
|
||||
@Override
|
||||
public int onStartCommand(@Nullable Intent intent, int flags, int startId) {
|
||||
MediaButtonReceiver.handleIntent(mediaSession, intent);
|
||||
if (intent != null) {
|
||||
if (intent.getAction() != null) {
|
||||
restoreQueuesAndPositionIfNecessary();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue