From bb7c934812ae86f9eef461278ef00fda9f4f6f1e Mon Sep 17 00:00:00 2001 From: bachinger Date: Tue, 13 Oct 2020 22:25:06 +0100 Subject: [PATCH] Add missing properties of MediaItem.Subtitle Issue: #8044 PiperOrigin-RevId: 336955479 --- .../google/android/exoplayer2/MediaItem.java | 34 +++++++++++++++++-- .../android/exoplayer2/MediaItemTest.java | 20 ++++++++--- .../source/SingleSampleMediaSource.java | 2 ++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/library/common/src/main/java/com/google/android/exoplayer2/MediaItem.java b/library/common/src/main/java/com/google/android/exoplayer2/MediaItem.java index 5a1265d856..53d81e9158 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/MediaItem.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/MediaItem.java @@ -778,6 +778,10 @@ public final class MediaItem { @Nullable public final String language; /** The selection flags. */ @C.SelectionFlags public final int selectionFlags; + /** The role flags. */ + @C.RoleFlags public final int roleFlags; + /** The label. */ + @Nullable public final String label; /** * Creates an instance. @@ -791,7 +795,7 @@ public final class MediaItem { } /** - * Creates an instance with the given selection flags. + * Creates an instance. * * @param uri The {@link Uri URI} to the subtitle file. * @param mimeType The MIME type. @@ -800,10 +804,32 @@ public final class MediaItem { */ public Subtitle( Uri uri, String mimeType, @Nullable String language, @C.SelectionFlags int selectionFlags) { + this(uri, mimeType, language, selectionFlags, /* roleFlags= */ 0, /* label= */ null); + } + + /** + * Creates an instance. + * + * @param uri The {@link Uri URI} to the subtitle file. + * @param mimeType The MIME type. + * @param language The optional language. + * @param selectionFlags The selection flags. + * @param roleFlags The role flags. + * @param label The optional label. + */ + public Subtitle( + Uri uri, + String mimeType, + @Nullable String language, + @C.SelectionFlags int selectionFlags, + @C.RoleFlags int roleFlags, + @Nullable String label) { this.uri = uri; this.mimeType = mimeType; this.language = language; this.selectionFlags = selectionFlags; + this.roleFlags = roleFlags; + this.label = label; } @Override @@ -820,7 +846,9 @@ public final class MediaItem { return uri.equals(other.uri) && mimeType.equals(other.mimeType) && Util.areEqual(language, other.language) - && selectionFlags == other.selectionFlags; + && selectionFlags == other.selectionFlags + && roleFlags == other.roleFlags + && Util.areEqual(label, other.label); } @Override @@ -829,6 +857,8 @@ public final class MediaItem { result = 31 * result + mimeType.hashCode(); result = 31 * result + (language == null ? 0 : language.hashCode()); result = 31 * result + selectionFlags; + result = 31 * result + roleFlags; + result = 31 * result + (label == null ? 0 : label.hashCode()); return result; } } diff --git a/library/common/src/test/java/com/google/android/exoplayer2/MediaItemTest.java b/library/common/src/test/java/com/google/android/exoplayer2/MediaItemTest.java index a9209fa920..31aa8bbff2 100644 --- a/library/common/src/test/java/com/google/android/exoplayer2/MediaItemTest.java +++ b/library/common/src/test/java/com/google/android/exoplayer2/MediaItemTest.java @@ -173,7 +173,14 @@ public class MediaItemTest { Uri.parse(URI_STRING + "/de"), MimeTypes.APPLICATION_TTML, /* language= */ null, - C.SELECTION_FLAG_DEFAULT)); + C.SELECTION_FLAG_DEFAULT), + new MediaItem.Subtitle( + Uri.parse(URI_STRING + "/fr"), + MimeTypes.APPLICATION_SUBRIP, + /* language= */ "fr", + C.SELECTION_FLAG_DEFAULT, + C.ROLE_FLAG_ALTERNATE, + "label")); MediaItem mediaItem = new MediaItem.Builder().setUri(URI_STRING).setSubtitles(subtitles).build(); @@ -336,15 +343,18 @@ public class MediaItemTest { .setMimeType(MimeTypes.APPLICATION_MP4) .setUri(URI_STRING) .setStreamKeys(Collections.singletonList(new StreamKey(1, 0, 0))) + .setLiveTargetOffsetMs(20_000) + .setLiveMinPlaybackSpeed(.9f) + .setLiveMaxPlaybackSpeed(1.1f) .setSubtitles( Collections.singletonList( new MediaItem.Subtitle( Uri.parse(URI_STRING + "/en"), MimeTypes.APPLICATION_TTML, - /* language= */ "en"))) - .setLiveTargetOffsetMs(20_000) - .setLiveMinPlaybackSpeed(.9f) - .setLiveMaxPlaybackSpeed(1.1f) + /* language= */ "en", + C.SELECTION_FLAG_FORCED, + C.ROLE_FLAG_ALTERNATE, + "label"))) .setTag(new Object()) .build(); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaSource.java b/library/core/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaSource.java index ab63ed83e6..6cb8a451b3 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaSource.java @@ -281,6 +281,8 @@ public final class SingleSampleMediaSource extends BaseMediaSource { .setSampleMimeType(subtitle.mimeType) .setLanguage(subtitle.language) .setSelectionFlags(subtitle.selectionFlags) + .setRoleFlags(subtitle.roleFlags) + .setLabel(subtitle.label) .build(); dataSpec = new DataSpec.Builder().setUri(subtitle.uri).setFlags(DataSpec.FLAG_ALLOW_GZIP).build();