From fc12457c7ea45cf15ff2ab7ee945e11971afd2f0 Mon Sep 17 00:00:00 2001 From: aquilescanta Date: Fri, 25 Oct 2019 11:16:04 +0100 Subject: [PATCH] Set internal state before setting up cast dependencies Prevents access of fields before initialization. Also set remoteMediaClient in the constructor by using setRemoteMediaClient instead of assigning the field directly, which will (if possible) pull the state of the receiver in the constructor. PiperOrigin-RevId: 276660004 --- .../google/android/exoplayer2/ext/cast/CastPlayer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java b/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java index 4fa1275f38..c198b49777 100644 --- a/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java +++ b/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java @@ -125,11 +125,6 @@ public final class CastPlayer extends BasePlayer { notificationsBatch = new ArrayList<>(); ongoingNotificationsTasks = new ArrayDeque<>(); - SessionManager sessionManager = castContext.getSessionManager(); - sessionManager.addSessionManagerListener(statusListener, CastSession.class); - CastSession session = sessionManager.getCurrentCastSession(); - remoteMediaClient = session != null ? session.getRemoteMediaClient() : null; - playWhenReady = new StateHolder<>(false); repeatMode = new StateHolder<>(REPEAT_MODE_OFF); playbackState = STATE_IDLE; @@ -138,6 +133,11 @@ public final class CastPlayer extends BasePlayer { currentTrackSelection = EMPTY_TRACK_SELECTION_ARRAY; pendingSeekWindowIndex = C.INDEX_UNSET; pendingSeekPositionMs = C.TIME_UNSET; + + SessionManager sessionManager = castContext.getSessionManager(); + sessionManager.addSessionManagerListener(statusListener, CastSession.class); + CastSession session = sessionManager.getCurrentCastSession(); + setRemoteMediaClient(session != null ? session.getRemoteMediaClient() : null); updateInternalStateAndNotifyIfChanged(); }