Skip to content

Commit eb1425e

Browse files
author
eunikolsky
committed
Merge pull request #31 from ConnectSDK/feature/subtitles
Add subtitle capability
2 parents b899a90 + f74a20b commit eb1425e

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ For more information, visit our [website](http://www.connectsdk.com/).
1010

1111
##Dependencies
1212
- [Android v7 appcompat library](http://developer.android.com/tools/support-library/features.html#v7-appcompat)
13-
- Android SDK v21 (the Sampler app targets v21, but works on v9 and greater)
13+
- Android SDK v22 (the Sampler app targets v22, but works on v10 and greater)
1414
- [Connect-SDK-Android-Core](https://github.com/ConnectSDK/Connect-SDK-Android-Core)
1515
- [Connect-SDK-Android-Google-Cast](https://github.com/ConnectSDK/Connect-SDK-Android-Google-Cast) for full version of Connect-SDK
1616

@@ -21,6 +21,9 @@ For more information, visit our [website](http://www.connectsdk.com/).
2121
```
2222
2. Import the Sampler project into Android Studio
2323
24+
##Using dev branch
25+
If you use dev branch you should [setup](https://github.com/ConnectSDK/Connect-SDK-Android#including-connect-sdk-in-your-app-with-android-studio-from-sources) Connect-SDK-Android from sources and you should use Connect-SDK-Android dev branch as well
26+
2427
##Contact
2528
* Twitter [@ConnectSDK](https://www.twitter.com/ConnectSDK)
2629
* Ask a question on Stack Overflow with the [Connect-SDK tag](https://stackoverflow.com/tags/connect-sdk) (or [TV tag](https://stackoverflow.com/tags/tv))

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

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import android.widget.TextView;
3232

3333
import com.connectsdk.core.MediaInfo;
34+
import com.connectsdk.core.SubtitleInfo;
3435
import com.connectsdk.device.ConnectableDevice;
3536
import com.connectsdk.sampler.R;
3637
import com.connectsdk.sampler.util.TestResponseObject;
@@ -56,6 +57,15 @@
5657
import java.util.concurrent.TimeUnit;
5758

5859
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+
5969
public Button photoButton;
6070
public Button videoButton;
6171
public Button audioButton;
@@ -387,12 +397,12 @@ private void showImage() {
387397
public void onSuccess(MediaLaunchObject object) {
388398
launchSession = object.launchSession;
389399
closeButton.setEnabled(true);
390-
testResponse = new TestResponseObject(true, TestResponseObject.SuccessCode, TestResponseObject.Display_image);
400+
testResponse = new TestResponseObject(true, TestResponseObject.SuccessCode, TestResponseObject.Display_image);
391401
closeButton.setOnClickListener(closeListener);
392402
stopUpdating();
393403
isPlayingImage = true;
394404
disconnectWebAppSession();
395-
405+
396406
}
397407

398408
@Override
@@ -401,29 +411,39 @@ public void onError(ServiceCommandError error) {
401411
if (launchSession != null) {
402412
launchSession.close(null);
403413
launchSession = null;
404-
testResponse = new TestResponseObject(false, error.getCode(), error.getMessage());
414+
testResponse = new TestResponseObject(false, error.getCode(), error.getMessage());
405415
stopUpdating();
406416
disableMedia();
407417
isPlaying = isPlayingImage = false;
408-
418+
409419
}
410420
}
411421
});
412422
}
413423

414424
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";
420425
boolean shouldLoop = loopingButton.isChecked();
421426

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() {
423443

424444
public void onSuccess(MediaLaunchObject object) {
425445
launchSession = object.launchSession;
426-
testResponse = new TestResponseObject(true, TestResponseObject.SuccessCode, TestResponseObject.Play_Video);
446+
testResponse = new TestResponseObject(true, TestResponseObject.SuccessCode, TestResponseObject.Play_Video);
427447
mMediaControl = object.mediaControl;
428448
mPlaylistControl = object.playlistControl;
429449
stopUpdating();
@@ -437,7 +457,7 @@ public void onError(ServiceCommandError error) {
437457
if (launchSession != null) {
438458
launchSession.close(null);
439459
launchSession = null;
440-
testResponse = new TestResponseObject(false, error.getCode(), error.getMessage());
460+
testResponse = new TestResponseObject(false, error.getCode(), error.getMessage());
441461
stopUpdating();
442462
disableMedia();
443463
isPlaying = isPlayingImage = false;

0 commit comments

Comments
 (0)