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.
This commit is contained in:
Tryton Van Meer 2017-10-08 09:23:05 -04:00 committed by Christian Schabesberger
parent 994559b39b
commit b70fd826e7
1 changed files with 4 additions and 0 deletions

View File

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