Review Fixes

This commit is contained in:
alexandre patelli 2018-03-11 19:23:00 +01:00
parent 1d629e7b2e
commit 36457400e7
2 changed files with 13 additions and 2 deletions

View File

@ -152,6 +152,7 @@ public final class BackgroundPlayer extends Service {
lockManager.releaseWifiAndCpu();
}
if (basePlayerImpl != null) {
basePlayerImpl.audioReactor.unregisterMediaButtonEventReceiver(mReceiverComponent);
basePlayerImpl.stopActivityBinding();
basePlayerImpl.destroy();
}
@ -160,8 +161,6 @@ public final class BackgroundPlayer extends Service {
basePlayerImpl = null;
lockManager = null;
basePlayerImpl.audioReactor.unregisterMediaButtonEventReceiver(mReceiverComponent);
stopForeground(true);
stopSelf();
}
@ -594,6 +593,10 @@ public final class BackgroundPlayer extends Service {
pendingIntent = PendingIntent.getBroadcast(context, NOTIFICATION_ID, new Intent(ACTION_PLAY_PREVIOUS), PendingIntent.FLAG_UPDATE_CURRENT);
} else if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
pendingIntent = PendingIntent.getBroadcast(context, NOTIFICATION_ID, new Intent(ACTION_PLAY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT);
} else if (keycode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) {
pendingIntent = PendingIntent.getBroadcast(context, NOTIFICATION_ID, new Intent(ACTION_FAST_FORWARD), PendingIntent.FLAG_UPDATE_CURRENT);
} else if (keycode == KeyEvent.KEYCODE_MEDIA_REWIND) {
pendingIntent = PendingIntent.getBroadcast(context, NOTIFICATION_ID, new Intent(ACTION_FAST_REWIND), PendingIntent.FLAG_UPDATE_CURRENT);
}
if (pendingIntent != null) {
try {

View File

@ -88,10 +88,18 @@ public class AudioReactor implements AudioManager.OnAudioFocusChangeListener, Au
}
public void registerMediaButtonEventReceiver(ComponentName componentName) {
if (android.os.Build.VERSION.SDK_INT > 27) {
Log.e(TAG, "registerMediaButtonEventReceiver has been deprecated and maybe not supported anymore.");
return;
}
audioManager.registerMediaButtonEventReceiver(componentName);
}
public void unregisterMediaButtonEventReceiver(ComponentName componentName) {
if (android.os.Build.VERSION.SDK_INT > 27) {
Log.e(TAG, "unregisterMediaButtonEventReceiver has been deprecated and maybe not supported anymore.");
return;
}
audioManager.unregisterMediaButtonEventReceiver(componentName);
}