From b70fd826e721e5bcf0e9341f7efa508ea687c53c Mon Sep 17 00:00:00 2001 From: Tryton Van Meer Date: Sun, 8 Oct 2017 09:23:05 -0400 Subject: [PATCH] Fix crash when returning to player. When switching apps or locking the phone, destroyPlayer is called which sets audioManager to null. So upon returning to the player and pressing play, the app crashes. So now initPlayer checks if audioManager is null and sets it if needed. --- app/src/main/java/org/schabi/newpipe/player/BasePlayer.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index 4b0604bb0..f90352fa1 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -178,6 +178,10 @@ public abstract class BasePlayer implements Player.EventListener, AudioManager.O if (DEBUG) Log.d(TAG, "initPlayer() called with: context = [" + context + "]"); initExoPlayerCache(); + if (audioManager == null) { + this.audioManager = ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE)); + } + AdaptiveTrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); DefaultTrackSelector defaultTrackSelector = new DefaultTrackSelector(trackSelectionFactory); DefaultLoadControl loadControl = new DefaultLoadControl();