Skip to content

Commit 3402ef4

Browse files
author
Eugene
committed
Merge pull request #33 from ConnectSDK/feature/add_subtitle_checkbox
Add subtitles checkbox
2 parents f9f85cb + a98e563 commit 3402ef4

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

res/layout/fragment_media_player.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@
108108
android:layout_weight="1"
109109
android:text="Playlist" />
110110

111+
<CheckBox
112+
android:id="@+id/subtitlesButton"
113+
android:layout_width="wrap_content"
114+
android:layout_height="wrap_content"
115+
android:paddingRight="5dp"
116+
android:text="Subtitles" />
117+
111118
<CheckBox
112119
android:id="@+id/loopingButton"
113120
android:layout_width="wrap_content"

src/com/connectsdk/sampler/fragments/MediaPlayerFragment.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public class MediaPlayerFragment extends BaseFragment {
8181
public Button nextButton;
8282
public Button jumpButton;
8383
public CheckBox loopingButton;
84+
public CheckBox subtitlesButton;
8485

8586
public LaunchSession launchSession;
8687

@@ -148,6 +149,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
148149
nextButton = (Button) rootView.findViewById(R.id.nextButton);
149150
jumpButton = (Button) rootView.findViewById(R.id.jumpButton);
150151
loopingButton = (CheckBox) rootView.findViewById(R.id.loopingButton);
152+
subtitlesButton = (CheckBox) rootView.findViewById(R.id.subtitlesButton);
151153

152154
positionTextView = (TextView) rootView.findViewById(R.id.stream_position);
153155
durationTextView = (TextView) rootView.findViewById(R.id.stream_duration);
@@ -173,6 +175,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
173175
nextButton,
174176
jumpButton,
175177
loopingButton,
178+
subtitlesButton,
176179
};
177180

178181
mHandler = new Handler();
@@ -226,6 +229,7 @@ public void onClick(View view) {
226229
totalTimeDuration = -1;
227230

228231
loopingButton.setEnabled(getTv().hasCapability(MediaPlayer.Loop));
232+
subtitlesButton.setEnabled(true);
229233

230234
if (getTv().hasCapability(MediaPlayer.Play_Video)) {
231235
videoButton.setEnabled(true);
@@ -399,19 +403,19 @@ public void onSuccess(MediaLaunchObject object) {
399403
private void playVideo() {
400404
boolean shouldLoop = loopingButton.isChecked();
401405

402-
SubtitleInfo.Builder subtitleBuilder;
403-
if (getTv().hasCapability(MediaPlayer.Subtitle_WebVTT)) {
404-
subtitleBuilder = new SubtitleInfo.Builder(URL_SUBTITLES_WEBVTT);
405-
} else {
406-
subtitleBuilder = new SubtitleInfo.Builder(URL_SUBTITLE_SRT);
406+
SubtitleInfo.Builder subtitleBuilder = null;
407+
if (subtitlesButton.isChecked()) {
408+
subtitleBuilder = new SubtitleInfo.Builder(
409+
getTv().hasCapability(MediaPlayer.Subtitle_WebVTT) ? URL_SUBTITLES_WEBVTT :
410+
URL_SUBTITLE_SRT);
411+
subtitleBuilder.setLabel("English").setLanguage("en");
407412
}
408-
subtitleBuilder.setLabel("English").setLanguage("en");
409413

410414
MediaInfo mediaInfo = new MediaInfo.Builder(URL_VIDEO_MP4, "video/mp4")
411415
.setTitle("Sintel Trailer")
412416
.setDescription("Blender Open Movie Project")
413417
.setIcon(URL_IMAGE_ICON)
414-
.setSubtitleInfo(subtitleBuilder.build())
418+
.setSubtitleInfo(subtitleBuilder == null ? null : subtitleBuilder.build())
415419
.build();
416420

417421
getMediaPlayer().playMedia(mediaInfo, shouldLoop, new MediaPlayer.LaunchListener() {
@@ -460,6 +464,7 @@ public void disableButtons() {
460464
positionTrackView.setEnabled(false);
461465

462466
loopingButton.setChecked(false);
467+
subtitlesButton.setEnabled(false);
463468
super.disableButtons();
464469
}
465470

0 commit comments

Comments
 (0)