FinishState.java
Overview
`FinishState.java` defines the **FinishState** class, a concrete implementation of a playback state within the Finite State Machine (FSM) for media playback in the Tubi TV player system. This state represents the terminal or end state in the media player’s lifecycle, typically reached when content playback has completed.
In the FSM playback flow, `FinishState` signifies that the media session has ended, and no further playback or ad-related transitions will occur. It extends from the abstract `BaseState` class, inheriting default behaviors but providing minimal additional logic since no further state transitions or player actions are expected after reaching this state.
Class: FinishState
Declaration
public class FinishState extends BaseState
**Inheritance:**
Extends
BaseStateImplements the
Stateinterface through inheritance
Purpose
Represents the terminal state after playback completion.
No further state transitions occur from this state.
Can perform any final cleanup or UI updates if necessary (none implemented here).
Signals the FSM that playback is finished.
Methods
1. transformToState
@Override
public State transformToState(Input input, StateFactory factory)
Description:
Determines the next state based on input events.
InFinishState, this method returnsnull, indicating no further transitions are possible or expected.Parameters:
Input input: An enum representing an event or trigger that might cause a state transition.StateFactory factory: Factory used to create or retrieve state instances.
Returns:
State: Always returnsnullin this class, meaning no next state.
Usage:
When the FSM calls this method on aFinishStateinstance, no state change occurs, effectively ending the FSM lifecycle.Example:
State nextState = finishState.transformToState(Input.AD_FINISH, stateFactory);
// nextState == null => no transition, playback ended
2. performWorkAndUpdatePlayerUI
@Override
public void performWorkAndUpdatePlayerUI(@NonNull FsmPlayer fsmPlayer)
Description:
Executes any work associated with this state and updates the player UI accordingly.Implementation Details:
Calls the superclass method (
BaseState.performWorkAndUpdatePlayerUI) for any shared behavior.Checks if the
fsmPlayerinstance isnull(usingisNull(fsmPlayer)), and if so, returns early without performing work.Contains no additional logic, as no active playback or UI updates are required in this terminal state.
Parameters:
@NonNull FsmPlayer fsmPlayer: The FSM player instance managing playback and UI.
Returns:
void
Usage Example:
Typically invoked by the FSM player when entering the finish state to allow any cleanup or final UI update (currently no additional work beyond base behavior).
Important Implementation Details
The
FinishStateis a leaf state in the FSM hierarchy: no outgoing transitions.It overrides
transformToStateto returnnull, preventing any further state changes.The
performWorkAndUpdatePlayerUImethod is effectively a no-op beyond the base behavior, reflecting that playback is complete.
Interaction with Other Components
FSM Player (
FsmPlayer)
When the FSM player transitions toFinishState, it stops further state transitions and playback operations. This state effectively marks the end of the media session lifecycle.StateFactory
TheStateFactorycan instantiate this state as part of transition flows, typically when theMOVIE_FINISHinput is processed by states likeMoviePlayingState.Other States
Other states transition toFinishStateupon receiving inputs indicating playback completion or terminal error conditions.UI Controllers and Player Logic
No direct UI or playback logic is executed in this state beyond whatBaseStateperforms. The player UI can be updated to reflect playback completion (e.g., showing replay options), but this is managed outside or in the base class.
Usage Example in FSM Flow
// Inside a state handling playback finish, such as MoviePlayingState
if (input == Input.MOVIE_FINISH) {
return stateFactory.createState(FinishState.class);
}
// FSM player transitions to FinishState and calls
finishState.performWorkAndUpdatePlayerUI(fsmPlayer);
This flow ensures that once playback finishes, the FSM is moved to `FinishState`, where the player can stop or show end-of-playback UI without further transitions.
Mermaid Class Diagram
classDiagram
class FinishState {
+State transformToState(Input input, StateFactory factory)
+void performWorkAndUpdatePlayerUI(FsmPlayer fsmPlayer)
}
FinishState --|> BaseState
Summary
FinishStaterepresents the final state in the FSM playback lifecycle.It does not permit any further transitions — its
transformToStatealways returnsnull.It inherits default UI update behavior from
BaseStatebut adds no additional logic.Used to mark playback completion and signal termination of the FSM player lifecycle.
Plays a critical role in cleanly ending playback sessions within the FSM architecture.
Appendix: Related States and Inputs (Context)
State Name | Purpose | Typical Transition to FinishState |
|---|---|---|
`MoviePlayingState` | Plays main content | On `Input.MOVIE_FINISH` |
Plays ads | On `Input.AD_FINISH` (then content or finish) | |
Plays interactive VPAID ads | On [Input.VPAID_FINISH](/projects/288/68335) | |
Other terminal states | May also transition to `FinishState` on errors or completion | Various terminal inputs |
Conclusion
`FinishState.java` is a simple yet essential component within the FSM-based media playback system representing the terminal state. Its minimal implementation is intentional to reflect the end of playback activities and prevent further FSM transitions, ensuring that the media player cleanly concludes the playback lifecycle.
*This documentation is intended for developers and maintainers working with the FSM playback module, providing clarity on the role and implementation of `FinishState` within the media player system.*