From 36457400e708dc284e2bbb219b472f8baf795aee Mon Sep 17 00:00:00 2001 From: alexandre patelli Date: Sun, 11 Mar 2018 19:23:00 +0100 Subject: [PATCH] Review Fixes --- .../java/org/schabi/newpipe/player/BackgroundPlayer.java | 7 +++++-- .../org/schabi/newpipe/player/helper/AudioReactor.java | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java index bc28116cd..3e9a63886 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -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 { diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java b/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java index 0e6642eed..df30c3e79 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java @@ -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); }