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
This commit is contained in:
aquilescanta 2019-10-25 11:16:04 +01:00 committed by Oliver Woodman
parent bcf46431dd
commit fc12457c7e

View file

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