From 1d629e7b2e40b70af56dbd490419486ebc098cf0 Mon Sep 17 00:00:00 2001 From: alexandre patelli Date: Sun, 11 Mar 2018 15:09:11 +0100 Subject: [PATCH] Direct use of AudioManager from AudioReactor --- .../java/org/schabi/newpipe/player/BackgroundPlayer.java | 7 ++----- .../org/schabi/newpipe/player/helper/AudioReactor.java | 9 +++++++++ 2 files changed, 11 insertions(+), 5 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 48249d876..bc28116cd 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -28,7 +28,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.graphics.Bitmap; -import android.media.AudioManager; import android.os.Build; import android.os.IBinder; import android.support.annotation.IntRange; @@ -82,7 +81,6 @@ public final class BackgroundPlayer extends Service { private BasePlayerImpl basePlayerImpl; private LockManager lockManager; - private AudioManager mAudioManager; private ComponentName mReceiverComponent; /*////////////////////////////////////////////////////////////////////////// @@ -122,9 +120,8 @@ public final class BackgroundPlayer extends Service { mBinder = new PlayerServiceBinder(basePlayerImpl); shouldUpdateOnProgress = true; - mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mReceiverComponent = new ComponentName(this, MediaButtonReceiver.class); - mAudioManager.registerMediaButtonEventReceiver(mReceiverComponent); + basePlayerImpl.audioReactor.registerMediaButtonEventReceiver(mReceiverComponent); } @Override @@ -163,7 +160,7 @@ public final class BackgroundPlayer extends Service { basePlayerImpl = null; lockManager = null; - mAudioManager.unregisterMediaButtonEventReceiver(mReceiverComponent); + basePlayerImpl.audioReactor.unregisterMediaButtonEventReceiver(mReceiverComponent); stopForeground(true); stopSelf(); 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 2c85cfc34..0e6642eed 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 @@ -3,6 +3,7 @@ package org.schabi.newpipe.player.helper; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.media.AudioFocusRequest; @@ -86,6 +87,14 @@ public class AudioReactor implements AudioManager.OnAudioFocusChangeListener, Au return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O; } + public void registerMediaButtonEventReceiver(ComponentName componentName) { + audioManager.registerMediaButtonEventReceiver(componentName); + } + + public void unregisterMediaButtonEventReceiver(ComponentName componentName) { + audioManager.unregisterMediaButtonEventReceiver(componentName); + } + /*////////////////////////////////////////////////////////////////////////// // AudioFocus //////////////////////////////////////////////////////////////////////////*/