SelectionActivity.java
Overview
`SelectionActivity` is a simple Android `Activity` that serves as a media selection interface within the Tubi TV media demo application. Its primary purpose is to present users with options to select video content and launch a specialized dual-player playback activity (`DoubleViewTubiPlayerActivity`) to play the selected media.
It provides two buttons, each mapped to a different video asset, which when clicked:
Create a
MediaModelobject encapsulating the video metadata (title, URL, artwork, subtitles).Construct an
Intenttargeting the dual-player activity.Attach the
MediaModelas an extra to the intent.Start the playback activity.
This file acts as an entry point for demonstrating and testing playback capabilities with different video sources, leveraging the dual ExoPlayer setup handled by `DoubleViewTubiPlayerActivity`.
Class: SelectionActivity
public class SelectionActivity extends Activity
Description
`SelectionActivity` extends Android's base `Activity` class and overrides the lifecycle method `onCreate()` to set up UI elements and define their behaviors. It does not maintain complex state or involve advanced business logic — its core function is to facilitate launching playback with predefined media selections.
Fields
Field Name | Type | Description |
|---|---|---|
`VIDEO_URL` | `String` | A static final string representing the base HLS video URL used by both selections. |
Methods
protected void onCreate(@Nullable Bundle savedInstanceState)
Description:
Lifecycle callback invoked when the activity is created. Sets up the UI layout, locates buttons by their IDs, and attaches click listeners to trigger playback.Parameters:
savedInstanceState: AndroidBundlecontaining saved state, if any.
Return:
None.
Implementation Details:
Sets the content view to
R.layout.activity_selection.Finds two buttons:
playHls1for the first video.playHls2for the second video.
For each button, sets an
OnClickListenerthat:Defines video metadata (name, artwork URL, subtitles URL if applicable).
Creates a
MediaModelinstance representing the video.Initiates an
Intentto launchDoubleViewTubiPlayerActivity.Passes the media model via intent extras.
Starts the activity.
Usage Example:
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selection);
Button playHls1 = findViewById(R.id.activity_selection_play_hls_1);
playHls1.setOnClickListener(v -> {
String subs = "http://s.adrise.tv/88703acf-66a2-4071-8231-d6cffe579f33.srt";
String artwork = "http://images.adrise.tv/6sjdZy7rGz23YZ62_diTF26BfgE=/214x306/smart/img.adrise.tv/4b85521c-c3af-41d5-bf52-40b698c6d56d.jpg";
String name = "longest weekend";
Intent intent = new Intent(SelectionActivity.this, DoubleViewTubiPlayerActivity.class);
intent.putExtra(TubiPlayerActivity.TUBI_MEDIA_KEY, MediaModel.video(name, VIDEO_URL, artwork, null));
startActivity(intent);
});
Button playHls2 = findViewById(R.id.activity_selection_play_hls_2);
playHls2.setOnClickListener(v -> {
String artwork = "http://images.adrise.tv/q4v7JUQPPHqn8nTmYiudW6l8w_0=/214x306/smart/img.adrise.tv/1c31dfce-5338-4a09-bcb0-f68789153f33.png";
String name = "Man on the ledge";
Intent intent = new Intent(SelectionActivity.this, DoubleViewTubiPlayerActivity.class);
intent.putExtra(TubiPlayerActivity.TUBI_MEDIA_KEY, MediaModel.video(name, VIDEO_URL, artwork, null));
startActivity(intent);
});
}
Important Implementation Details
MediaModel Creation:
The activity uses a static factory methodMediaModel.video(name, url, artwork, subtitles)to create media model instances that encapsulate all necessary metadata for playback, including video URL, artwork image, and optional subtitles.Intent Extras:
The media model is passed as an extra in the intent using the keyTubiPlayerActivity.TUBI_MEDIA_KEY. This key is expected byDoubleViewTubiPlayerActivityto retrieve the media information and initiate playback accordingly.Hardcoded Video URL:
The video URL used in both buttons points to a sample HLS stream hosted by Apple (master.m3u8). This is a demo URL to showcase HLS playback.UI Layout Dependency:
The activity depends on the layout resourceactivity_selection.xml, which must define at least two buttons with IDsactivity_selection_play_hls_1andactivity_selection_play_hls_2.
Interaction with Other Parts of the System
DoubleViewTubiPlayerActivity:
This activity is the main playback component that manages two ExoPlayer instances simultaneously for content and ads.SelectionActivitylaunches this activity with the selected media model to start playback.MediaModel:
A data model class representing video assets. It encapsulates video URL, artwork, subtitles, and title. The model is serialized and passed between activities.TubiPlayerActivity.TUBI_MEDIA_KEY:
A constant key used for intent extras to identify the media model payload.UI Resources:
Depends on XML layout resources and button IDs for user interaction.
Diagram: Class Structure of SelectionActivity.java
classDiagram
class SelectionActivity {
-VIDEO_URL: String
+onCreate(savedInstanceState: Bundle)
}
This diagram shows the single class `SelectionActivity`, its static string field `VIDEO_URL`, and the overridden lifecycle method `onCreate`.
Summary
`SelectionActivity.java` is a straightforward Android activity that provides a minimal but functional media selection interface. It demonstrates how to:
Define UI controls for media selection.
Construct media metadata models.
Launch a complex playback activity (
DoubleViewTubiPlayerActivity) with the selected media.
It acts as a bridge between user interaction and the advanced dual-player playback system, enabling easy testing and demonstration of video playback with different media assets.
Usage Notes
To extend this activity with more media options, simply add more buttons and replicate the click listener pattern with different
MediaModelconfigurations.Ensure that the target playback activity (
DoubleViewTubiPlayerActivity) supports the media model passed and handles playback correctly.The current implementation uses hardcoded URLs and metadata. For a production app, consider fetching media data dynamically from a backend service or local database.
Appendix: Media Selection to Playback Flow
flowchart TD
User[User taps selection button]
MediaModel[Create MediaModel with metadata]
Intent[Create Intent with MediaModel extra]
PlaybackActivity[Start DoubleViewTubiPlayerActivity]
Retrieve[Retrieve MediaModel in player]
FSM[Initialize FSM with media]
Playback[Start playback with dual ExoPlayers]
User --> MediaModel --> Intent --> PlaybackActivity --> Retrieve --> FSM --> Playback
This flowchart illustrates the process from user interaction within `SelectionActivity` through to media playback initiation in the dual-player activity.
End of documentation for **SelectionActivity.java**.