TubiPlaybackControlInterface.java
Overview
`TubiPlaybackControlInterface` is a Java interface within the `com.tubitv.media.interfaces` package that defines a contract for controlling video playback behavior in the Tubi TV media player application. It abstracts essential playback control operations such as play/pause toggling, seeking within the video, subtitle management, and ad interactions, as well as playback state queries related to the current media item.
This interface enables different playback controller implementations to provide consistent control functionality while isolating the rest of the application from the underlying playback engine details. It primarily serves as a bridge between the user interface components and the playback logic, supporting modularity and ease of testing.
Detailed Explanation of Interface Methods
Action Control Methods
These methods control playback actions or trigger user interactions.
Method Signature | Description | Parameters | Return Type | Usage Example |
|---|---|---|---|---|
`void triggerSubtitlesToggle(boolean enabled)` | Enables or disables subtitles for the current video playback. | `enabled` - `true` to enable subtitles, `false` to disable | `void` | `playbackControl.triggerSubtitlesToggle(true);` enables subtitles during playback. |
`void seekBy(long millisecond)` | Moves the playback position forward or backward relative to the current position by the specified milliseconds. | `millisecond` - positive to seek forward, negative to seek backward | `void` | `playbackControl.seekBy(15000);` skips forward 15 seconds in the video. |
`void seekTo(long millisecond)` | Jumps directly to an absolute playback position in milliseconds. | `millisecond` - absolute position in the video timeline | `void` | `playbackControl.seekTo(60000);` jumps to the 1-minute mark in the video. |
`void triggerPlayOrPause(boolean setPlay)` | Starts or pauses video playback based on the boolean flag. | `setPlay` - `true` to play, `false` to pause | `void` | `playbackControl.triggerPlayOrPause(false);` pauses the video playback. |
`void clickCurrentAd()` | Simulates a click interaction on the currently playing advertisement, if applicable. | None | `void` | `playbackControl.clickCurrentAd();` triggers ad click actions such as opening advertiser links. |
Display Control / Playback State Query Methods
These methods retrieve information about the current playback state or media.
Method Signature | Description | Parameters | Return Type | Usage Example |
|---|---|---|---|---|
`String getCurrentVideoName()` | Returns the title or identifier of the currently playing video. | None | `String` | `String title = playbackControl.getCurrentVideoName();` |
`boolean isPlayWhenReady()` | Indicates whether the player is set to start playing as soon as it is ready (buffered). | None | `boolean` | |
`boolean isCurrentVideoAd()` | Checks if the currently playing video is an advertisement. | None | `boolean` | `if(playbackControl.isCurrentVideoAd()) { /* handle ad-specific logic */ }` |
`long currentDuration()` | Returns the total duration of the current video in milliseconds. | None | `long` | `long durationMs = playbackControl.currentDuration();` |
`long currentProgressPosition()` | Returns the current playback position in milliseconds. | None | `long` | `long currentPositionMs = playbackControl.currentProgressPosition();` |
`long currentBufferPosition()` | Returns the position up to which the video has been buffered in milliseconds. | None | `long` | `long bufferedUpToMs = playbackControl.currentBufferPosition();` |
Implementation Details and Algorithms
This interface does not provide concrete implementations but defines the methods that any playback controller must implement.
Implementations will typically interact with a media player engine (e.g., ExoPlayer, MediaPlayer) to perform actual playback control operations.
Methods like
seekByandseekTorely on the underlying player’s seeking capabilities.clickCurrentAd()suggests that the playback layer supports interactive advertising, possibly triggering ad clickthroughs or tracking.Playback state query methods support UI components in displaying accurate playback progress, buffering status, and media info.
The interface design promotes clean separation of concerns by isolating playback commands and queries from UI or business logic layers.
Interaction with Other System Components
User Interface Layer:
UI components such as playback controls, progress bars, subtitle toggles, and ad overlays invoke this interface to control playback behavior and retrieve playback status for display.Playback Engine Layer:
Concrete implementations of this interface interact directly with the media playback engine/library, translating UI commands into player actions and extracting state.Ad Management System:
TheclickCurrentAd()method indicates integration with an ad management or tracking subsystem, allowing user interactions on ads to be captured and processed.Subtitle Rendering Subsystem:
The subtitle toggle method helps coordinate subtitle visibility with the subtitle renderer.
This interface acts as a contract enabling loose coupling and easier testing/mocking in the media player’s architecture.
Usage Example
public class MyPlaybackController implements TubiPlaybackControlInterface {
// Assume mediaPlayer is an instance of a media player engine (e.g., ExoPlayer)
@Override
public void triggerSubtitlesToggle(boolean enabled) {
// Enable or disable subtitle rendering
subtitleRenderer.setVisible(enabled);
}
@Override
public void seekBy(long millisecond) {
long newPosition = mediaPlayer.getCurrentPosition() + millisecond;
mediaPlayer.seekTo(newPosition);
}
@Override
public void seekTo(long millisecond) {
mediaPlayer.seekTo(millisecond);
}
@Override
public void triggerPlayOrPause(boolean setPlay) {
if(setPlay) {
mediaPlayer.play();
} else {
mediaPlayer.pause();
}
}
@Override
public void clickCurrentAd() {
adManager.handleClick();
}
@Override
public String getCurrentVideoName() {
return mediaPlayer.getCurrentMediaMetadata().title;
}
@Override
public boolean isPlayWhenReady() {
return mediaPlayer.isPlaying();
}
@Override
public boolean isCurrentVideoAd() {
return adManager.isAdPlaying();
}
@Override
public long currentDuration() {
return mediaPlayer.getDuration();
}
@Override
public long currentProgressPosition() {
return mediaPlayer.getCurrentPosition();
}
@Override
public long currentBufferPosition() {
return mediaPlayer.getBufferedPosition();
}
}
Mermaid Class Diagram
classDiagram
class TubiPlaybackControlInterface {
<<interface>>
+void triggerSubtitlesToggle(enabled: boolean)
+void seekBy(millisecond: long)
+void seekTo(millisecond: long)
+void triggerPlayOrPause(setPlay: boolean)
+void clickCurrentAd()
+String getCurrentVideoName()
+boolean isPlayWhenReady()
+boolean isCurrentVideoAd()
+long currentDuration()
+long currentProgressPosition()
+long currentBufferPosition()
}
Summary
`TubiPlaybackControlInterface` is a pivotal interface in the Tubi TV media player architecture, defining essential playback control and state query operations. It abstracts the interaction between the UI layer and the underlying media playback engine, enabling consistent and flexible control of video playback, subtitle toggling, seeking, and ad interaction. Its design supports modularity and clean separation of concerns, facilitating maintainability and future enhancements within the playback system.