@@ -81,6 +81,7 @@ public class MediaPlayerFragment extends BaseFragment {
81
81
public Button nextButton ;
82
82
public Button jumpButton ;
83
83
public CheckBox loopingButton ;
84
+ public CheckBox subtitlesButton ;
84
85
85
86
public LaunchSession launchSession ;
86
87
@@ -148,6 +149,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
148
149
nextButton = (Button ) rootView .findViewById (R .id .nextButton );
149
150
jumpButton = (Button ) rootView .findViewById (R .id .jumpButton );
150
151
loopingButton = (CheckBox ) rootView .findViewById (R .id .loopingButton );
152
+ subtitlesButton = (CheckBox ) rootView .findViewById (R .id .subtitlesButton );
151
153
152
154
positionTextView = (TextView ) rootView .findViewById (R .id .stream_position );
153
155
durationTextView = (TextView ) rootView .findViewById (R .id .stream_duration );
@@ -173,6 +175,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
173
175
nextButton ,
174
176
jumpButton ,
175
177
loopingButton ,
178
+ subtitlesButton ,
176
179
};
177
180
178
181
mHandler = new Handler ();
@@ -226,6 +229,7 @@ public void onClick(View view) {
226
229
totalTimeDuration = -1 ;
227
230
228
231
loopingButton .setEnabled (getTv ().hasCapability (MediaPlayer .Loop ));
232
+ subtitlesButton .setEnabled (true );
229
233
230
234
if (getTv ().hasCapability (MediaPlayer .Play_Video )) {
231
235
videoButton .setEnabled (true );
@@ -399,19 +403,19 @@ public void onSuccess(MediaLaunchObject object) {
399
403
private void playVideo () {
400
404
boolean shouldLoop = loopingButton .isChecked ();
401
405
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" );
407
412
}
408
- subtitleBuilder .setLabel ("English" ).setLanguage ("en" );
409
413
410
414
MediaInfo mediaInfo = new MediaInfo .Builder (URL_VIDEO_MP4 , "video/mp4" )
411
415
.setTitle ("Sintel Trailer" )
412
416
.setDescription ("Blender Open Movie Project" )
413
417
.setIcon (URL_IMAGE_ICON )
414
- .setSubtitleInfo (subtitleBuilder .build ())
418
+ .setSubtitleInfo (subtitleBuilder == null ? null : subtitleBuilder .build ())
415
419
.build ();
416
420
417
421
getMediaPlayer ().playMedia (mediaInfo , shouldLoop , new MediaPlayer .LaunchListener () {
@@ -460,6 +464,7 @@ public void disableButtons() {
460
464
positionTrackView .setEnabled (false );
461
465
462
466
loopingButton .setChecked (false );
467
+ subtitlesButton .setEnabled (false );
463
468
super .disableButtons ();
464
469
}
465
470
0 commit comments