Class PlaybackStateMachine
java.lang.Object
com.castlabs.android.player.state.PlaybackStateMachine
Turns player events into changes in the shared playback state model.
Command and lifecycle methods describe work accepted by PlayerController. Playback
methods include a session ID so callbacks from an old player can be ignored. The dispatcher
handles every input in order before this class reads or changes its state.
-
Constructor Summary
ConstructorsConstructorDescriptionPlaybackStateMachine(Handler handler, PlaybackStateListener listener) Creates a state machine. -
Method Summary
Modifier and TypeMethodDescriptiongetState()Returns the current shared playback state.voidonContentEnded(int sessionId, long currentPositionMs, long durationMs) Reports that the content, rather than an ad, reached its end.voidonDataAvailable(int sessionId, PlaybackStateTransitionReason adReason) Reports that the player has enough data for the current position.voidonDataUnavailable(int sessionId, boolean loading, long currentPositionMs, long bufferedPositionMs, PlaybackStateTransitionReason adReason) Reports that playback needs data.voidReports a fatal error and moves the state toError.voidonOpenAccepted(int sessionId, boolean autoplay) Starts a new playback-state session after the controller accepts an open call.voidReports that the controller accepted a request to pause playback.voidonPlaybackStoppedWithoutResume(int sessionId, PlaybackStateTransitionReason adReason) Reports that playback is not running and will not restart automatically.voidonPlaybackTemporarilySuppressed(int sessionId, PlaybackStateTransitionReason adReason) Reports that playback is temporarily blocked and will be retried automatically.voidonPlayingObserved(int sessionId, PlaybackStateTransitionReason adReason) Reports that the player is or was actually playing in the current callback batch.voidReports that the controller accepted a request to start playback.voidReports that release has finished, moves the state toIdle, and clears the session.voidReports that release has started and moves the state toStopping.voidonSeekAccepted(long currentPositionMs, long targetPositionMs, long durationMs, long bufferedPositionMs, long backBufferDurationMs, boolean deferUntilEnded, boolean internalSeekToEnd) Saves a seek when the controller accepts it.voidReports that the first usable track model for the current open is ready.
-
Constructor Details
-
PlaybackStateMachine
Creates a state machine.- Parameters:
handler- handler used to process state changes and call the listenerlistener- listener called for each state change
-
-
Method Details
-
getState
Returns the current shared playback state.- Returns:
- current state
-
onOpenAccepted
public void onOpenAccepted(int sessionId, boolean autoplay) Starts a new playback-state session after the controller accepts an open call.- Parameters:
sessionId- ID used to reject callbacks from an older playerautoplay- whether the open call requested autoplay
-
onTrackModelReady
public void onTrackModelReady()Reports that the first usable track model for the current open is ready. -
onPlayRequested
public void onPlayRequested()Reports that the controller accepted a request to start playback. -
onPauseRequested
public void onPauseRequested()Reports that the controller accepted a request to pause playback. -
onSeekAccepted
public void onSeekAccepted(long currentPositionMs, long targetPositionMs, long durationMs, long bufferedPositionMs, long backBufferDurationMs, boolean deferUntilEnded, boolean internalSeekToEnd) Saves a seek when the controller accepts it.The position, duration, and buffer values are taken before the player handles the seek. They are used later to decide whether loading was needed and to build seek event data.
- Parameters:
currentPositionMs- content position before the seektargetPositionMs- requested content positiondurationMs- content duration, or a negative value when unknownbufferedPositionMs- end of the buffered content, or a negative value when unknownbackBufferDurationMs- amount of buffered content kept before the current positiondeferUntilEnded- whether the previous playback must enterEndedfirstinternalSeekToEnd- whether the controller made this seek as part of its end handling
-
onDataAvailable
Reports that the player has enough data for the current position.- Parameters:
sessionId- ID of the player that sent this updateadReason- ad start or stop reason from the same callback batch, ornull
-
onPlaybackTemporarilySuppressed
public void onPlaybackTemporarilySuppressed(int sessionId, @Nullable PlaybackStateTransitionReason adReason) Reports that playback is temporarily blocked and will be retried automatically.- Parameters:
sessionId- ID of the player that sent this updateadReason- ad start or stop reason from the same callback batch, ornull
-
onPlaybackStoppedWithoutResume
public void onPlaybackStoppedWithoutResume(int sessionId, @Nullable PlaybackStateTransitionReason adReason) Reports that playback is not running and will not restart automatically.- Parameters:
sessionId- ID of the player that sent this updateadReason- ad start or stop reason from the same callback batch, ornull
-
onPlayingObserved
Reports that the player is or was actually playing in the current callback batch.- Parameters:
sessionId- ID of the player that sent this updateadReason- ad start or stop reason from the same callback batch, ornull
-
onContentEnded
public void onContentEnded(int sessionId, long currentPositionMs, long durationMs) Reports that the content, rather than an ad, reached its end.- Parameters:
sessionId- ID of the player that sent this updatecurrentPositionMs- content position when the end was reporteddurationMs- content duration, or a negative value when unknown
-
onReleaseStarted
public void onReleaseStarted()Reports that release has started and moves the state toStopping. -
onReleaseCompleted
public void onReleaseCompleted()Reports that release has finished, moves the state toIdle, and clears the session. -
onFatalError
public void onFatalError()Reports a fatal error and moves the state toError.
-