1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 16:40:32 +00:00

Direct use of AudioManager from AudioReactor

This commit is contained in:
alexandre patelli 2018-03-11 15:09:11 +01:00
parent 5f764ab8f5
commit 1d629e7b2e
2 changed files with 11 additions and 5 deletions

View File

@ -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();

View File

@ -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
//////////////////////////////////////////////////////////////////////////*/