31
31
import android .widget .TextView ;
32
32
33
33
import com .connectsdk .core .MediaInfo ;
34
+ import com .connectsdk .core .SubtitleInfo ;
34
35
import com .connectsdk .device .ConnectableDevice ;
35
36
import com .connectsdk .sampler .R ;
36
37
import com .connectsdk .sampler .util .TestResponseObject ;
56
57
import java .util .concurrent .TimeUnit ;
57
58
58
59
public class MediaPlayerFragment extends BaseFragment {
60
+ public static final String URL_SUBTITLES_WEBVTT =
61
+ "http://ec2-54-201-108-205.us-west-2.compute.amazonaws.com/samples/media/sintel_en.vtt" ;
62
+ public static final String URL_SUBTITLE_SRT =
63
+ "http://ec2-54-201-108-205.us-west-2.compute.amazonaws.com/samples/media/sintel_en.srt" ;
64
+ public static final String URL_VIDEO_MP4 =
65
+ "http://ec2-54-201-108-205.us-west-2.compute.amazonaws.com/samples/media/video.mp4" ;
66
+ public static final String URL_IMAGE_ICON =
67
+ "http://ec2-54-201-108-205.us-west-2.compute.amazonaws.com/samples/media/videoIcon.jpg" ;
68
+
59
69
public Button photoButton ;
60
70
public Button videoButton ;
61
71
public Button audioButton ;
@@ -387,12 +397,12 @@ private void showImage() {
387
397
public void onSuccess (MediaLaunchObject object ) {
388
398
launchSession = object .launchSession ;
389
399
closeButton .setEnabled (true );
390
- testResponse = new TestResponseObject (true , TestResponseObject .SuccessCode , TestResponseObject .Display_image );
400
+ testResponse = new TestResponseObject (true , TestResponseObject .SuccessCode , TestResponseObject .Display_image );
391
401
closeButton .setOnClickListener (closeListener );
392
402
stopUpdating ();
393
403
isPlayingImage = true ;
394
404
disconnectWebAppSession ();
395
-
405
+
396
406
}
397
407
398
408
@ Override
@@ -401,29 +411,39 @@ public void onError(ServiceCommandError error) {
401
411
if (launchSession != null ) {
402
412
launchSession .close (null );
403
413
launchSession = null ;
404
- testResponse = new TestResponseObject (false , error .getCode (), error .getMessage ());
414
+ testResponse = new TestResponseObject (false , error .getCode (), error .getMessage ());
405
415
stopUpdating ();
406
416
disableMedia ();
407
417
isPlaying = isPlayingImage = false ;
408
-
418
+
409
419
}
410
420
}
411
421
});
412
422
}
413
423
414
424
private void playVideo () {
415
- String videoPath = "http://ec2-54-201-108-205.us-west-2.compute.amazonaws.com/samples/media/video.mp4" ;
416
- String mimeType = "video/mp4" ;
417
- String title = "Sintel Trailer" ;
418
- String description = "Blender Open Movie Project" ;
419
- String icon = "http://ec2-54-201-108-205.us-west-2.compute.amazonaws.com/samples/media/videoIcon.jpg" ;
420
425
boolean shouldLoop = loopingButton .isChecked ();
421
426
422
- getMediaPlayer ().playMedia (videoPath , mimeType , title , description , icon , shouldLoop , new MediaPlayer .LaunchListener () {
427
+ SubtitleInfo .Builder subtitleBuilder ;
428
+ if (getTv ().hasCapability (MediaPlayer .Subtitle_WebVTT )) {
429
+ subtitleBuilder = new SubtitleInfo .Builder (URL_SUBTITLES_WEBVTT );
430
+ } else {
431
+ subtitleBuilder = new SubtitleInfo .Builder (URL_SUBTITLE_SRT );
432
+ }
433
+ subtitleBuilder .setLabel ("English" ).setLanguage ("en" );
434
+
435
+ MediaInfo mediaInfo = new MediaInfo .Builder (URL_VIDEO_MP4 , "video/mp4" )
436
+ .setTitle ("Sintel Trailer" )
437
+ .setDescription ("Blender Open Movie Project" )
438
+ .setIcon (URL_IMAGE_ICON )
439
+ .setSubtitleInfo (subtitleBuilder .build ())
440
+ .build ();
441
+
442
+ getMediaPlayer ().playMedia (mediaInfo , shouldLoop , new MediaPlayer .LaunchListener () {
423
443
424
444
public void onSuccess (MediaLaunchObject object ) {
425
445
launchSession = object .launchSession ;
426
- testResponse = new TestResponseObject (true , TestResponseObject .SuccessCode , TestResponseObject .Play_Video );
446
+ testResponse = new TestResponseObject (true , TestResponseObject .SuccessCode , TestResponseObject .Play_Video );
427
447
mMediaControl = object .mediaControl ;
428
448
mPlaylistControl = object .playlistControl ;
429
449
stopUpdating ();
@@ -437,7 +457,7 @@ public void onError(ServiceCommandError error) {
437
457
if (launchSession != null ) {
438
458
launchSession .close (null );
439
459
launchSession = null ;
440
- testResponse = new TestResponseObject (false , error .getCode (), error .getMessage ());
460
+ testResponse = new TestResponseObject (false , error .getCode (), error .getMessage ());
441
461
stopUpdating ();
442
462
disableMedia ();
443
463
isPlaying = isPlayingImage = false ;
0 commit comments