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 dfff9a9e73..556b04b8ca 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 @@ -669,6 +669,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. @@ -682,7 +686,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. @@ -691,10 +695,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 @@ -711,7 +737,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 @@ -720,6 +748,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 86f03a3ddb..5d00b1e3dd 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(); @@ -317,7 +324,10 @@ public class MediaItemTest { new MediaItem.Subtitle( Uri.parse(URI_STRING + "/en"), MimeTypes.APPLICATION_TTML, - /* language= */ "en"))) + /* 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();