Commit fc12457c by aquilescanta Committed by Oliver Woodman

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
parent bcf46431
...@@ -125,11 +125,6 @@ public final class CastPlayer extends BasePlayer { ...@@ -125,11 +125,6 @@ public final class CastPlayer extends BasePlayer {
notificationsBatch = new ArrayList<>(); notificationsBatch = new ArrayList<>();
ongoingNotificationsTasks = new ArrayDeque<>(); 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); playWhenReady = new StateHolder<>(false);
repeatMode = new StateHolder<>(REPEAT_MODE_OFF); repeatMode = new StateHolder<>(REPEAT_MODE_OFF);
playbackState = STATE_IDLE; playbackState = STATE_IDLE;
...@@ -138,6 +133,11 @@ public final class CastPlayer extends BasePlayer { ...@@ -138,6 +133,11 @@ public final class CastPlayer extends BasePlayer {
currentTrackSelection = EMPTY_TRACK_SELECTION_ARRAY; currentTrackSelection = EMPTY_TRACK_SELECTION_ARRAY;
pendingSeekWindowIndex = C.INDEX_UNSET; pendingSeekWindowIndex = C.INDEX_UNSET;
pendingSeekPositionMs = C.TIME_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(); updateInternalStateAndNotifyIfChanged();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment