Add MediaItem.SubtitleConfiguration#id field

Issue: google/ExoPlayer#9673

#minor-release

PiperOrigin-RevId: 414413320
This commit is contained in:
ibaker 2021-12-06 13:24:26 +00:00 committed by Ian Baker
parent 1b0742f54a
commit 59d98b9a4e
4 changed files with 28 additions and 5 deletions

View File

@ -1268,6 +1268,7 @@ public final class MediaItem implements Bundleable {
private @C.SelectionFlags int selectionFlags; private @C.SelectionFlags int selectionFlags;
private @C.RoleFlags int roleFlags; private @C.RoleFlags int roleFlags;
@Nullable private String label; @Nullable private String label;
@Nullable private String id;
/** /**
* Constructs an instance. * Constructs an instance.
@ -1285,6 +1286,7 @@ public final class MediaItem implements Bundleable {
this.selectionFlags = subtitleConfiguration.selectionFlags; this.selectionFlags = subtitleConfiguration.selectionFlags;
this.roleFlags = subtitleConfiguration.roleFlags; this.roleFlags = subtitleConfiguration.roleFlags;
this.label = subtitleConfiguration.label; this.label = subtitleConfiguration.label;
this.id = subtitleConfiguration.id;
} }
/** Sets the {@link Uri} to the subtitle file. */ /** Sets the {@link Uri} to the subtitle file. */
@ -1323,6 +1325,12 @@ public final class MediaItem implements Bundleable {
return this; return this;
} }
/** Sets the optional ID for this subtitle track. */
public Builder setId(@Nullable String id) {
this.id = id;
return this;
}
/** Creates a {@link SubtitleConfiguration} from the values of this builder. */ /** Creates a {@link SubtitleConfiguration} from the values of this builder. */
public SubtitleConfiguration build() { public SubtitleConfiguration build() {
return new SubtitleConfiguration(this); return new SubtitleConfiguration(this);
@ -1345,20 +1353,27 @@ public final class MediaItem implements Bundleable {
public final @C.RoleFlags int roleFlags; public final @C.RoleFlags int roleFlags;
/** The label. */ /** The label. */
@Nullable public final String label; @Nullable public final String label;
/**
* The ID of the subtitles. This will be propagated to the {@link Format#id} of the subtitle
* track created from this configuration.
*/
@Nullable public final String id;
private SubtitleConfiguration( private SubtitleConfiguration(
Uri uri, Uri uri,
String mimeType, String mimeType,
@Nullable String language, @Nullable String language,
@C.SelectionFlags int selectionFlags, int selectionFlags,
@C.RoleFlags int roleFlags, int roleFlags,
@Nullable String label) { @Nullable String label,
@Nullable String id) {
this.uri = uri; this.uri = uri;
this.mimeType = mimeType; this.mimeType = mimeType;
this.language = language; this.language = language;
this.selectionFlags = selectionFlags; this.selectionFlags = selectionFlags;
this.roleFlags = roleFlags; this.roleFlags = roleFlags;
this.label = label; this.label = label;
this.id = id;
} }
private SubtitleConfiguration(Builder builder) { private SubtitleConfiguration(Builder builder) {
@ -1368,6 +1383,7 @@ public final class MediaItem implements Bundleable {
this.selectionFlags = builder.selectionFlags; this.selectionFlags = builder.selectionFlags;
this.roleFlags = builder.roleFlags; this.roleFlags = builder.roleFlags;
this.label = builder.label; this.label = builder.label;
this.id = builder.id;
} }
/** Returns a {@link Builder} initialized with the values of this instance. */ /** Returns a {@link Builder} initialized with the values of this instance. */
@ -1391,7 +1407,8 @@ public final class MediaItem implements Bundleable {
&& Util.areEqual(language, other.language) && Util.areEqual(language, other.language)
&& selectionFlags == other.selectionFlags && selectionFlags == other.selectionFlags
&& roleFlags == other.roleFlags && roleFlags == other.roleFlags
&& Util.areEqual(label, other.label); && Util.areEqual(label, other.label)
&& Util.areEqual(id, other.id);
} }
@Override @Override
@ -1402,6 +1419,7 @@ public final class MediaItem implements Bundleable {
result = 31 * result + selectionFlags; result = 31 * result + selectionFlags;
result = 31 * result + roleFlags; result = 31 * result + roleFlags;
result = 31 * result + (label == null ? 0 : label.hashCode()); result = 31 * result + (label == null ? 0 : label.hashCode());
result = 31 * result + (id == null ? 0 : id.hashCode());
return result; return result;
} }
} }
@ -1436,7 +1454,7 @@ public final class MediaItem implements Bundleable {
@C.SelectionFlags int selectionFlags, @C.SelectionFlags int selectionFlags,
@C.RoleFlags int roleFlags, @C.RoleFlags int roleFlags,
@Nullable String label) { @Nullable String label) {
super(uri, mimeType, language, selectionFlags, roleFlags, label); super(uri, mimeType, language, selectionFlags, roleFlags, label, /* id= */ null);
} }
private Subtitle(Builder builder) { private Subtitle(Builder builder) {

View File

@ -276,6 +276,7 @@ public class MediaItemTest {
.setSelectionFlags(C.SELECTION_FLAG_FORCED) .setSelectionFlags(C.SELECTION_FLAG_FORCED)
.setRoleFlags(C.ROLE_FLAG_ALTERNATE) .setRoleFlags(C.ROLE_FLAG_ALTERNATE)
.setLabel("label") .setLabel("label")
.setId("id")
.build()); .build());
MediaItem mediaItem = MediaItem mediaItem =
@ -617,6 +618,7 @@ public class MediaItemTest {
.setSelectionFlags(C.SELECTION_FLAG_FORCED) .setSelectionFlags(C.SELECTION_FLAG_FORCED)
.setRoleFlags(C.ROLE_FLAG_ALTERNATE) .setRoleFlags(C.ROLE_FLAG_ALTERNATE)
.setLabel("label") .setLabel("label")
.setId("id")
.build())) .build()))
.setTag(new Object()) .setTag(new Object())
.build(); .build();
@ -673,6 +675,7 @@ public class MediaItemTest {
.setSelectionFlags(C.SELECTION_FLAG_FORCED) .setSelectionFlags(C.SELECTION_FLAG_FORCED)
.setRoleFlags(C.ROLE_FLAG_ALTERNATE) .setRoleFlags(C.ROLE_FLAG_ALTERNATE)
.setLabel("label") .setLabel("label")
.setId("id")
.build())) .build()))
.setTag(new Object()) .setTag(new Object())
.build(); .build();

View File

@ -406,6 +406,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
.setSelectionFlags(subtitleConfigurations.get(i).selectionFlags) .setSelectionFlags(subtitleConfigurations.get(i).selectionFlags)
.setRoleFlags(subtitleConfigurations.get(i).roleFlags) .setRoleFlags(subtitleConfigurations.get(i).roleFlags)
.setLabel(subtitleConfigurations.get(i).label) .setLabel(subtitleConfigurations.get(i).label)
.setId(subtitleConfigurations.get(i).id)
.build(); .build();
ExtractorsFactory extractorsFactory = ExtractorsFactory extractorsFactory =
() -> () ->

View File

@ -172,6 +172,7 @@ public final class SingleSampleMediaSource extends BaseMediaSource {
.setSelectionFlags(subtitleConfiguration.selectionFlags) .setSelectionFlags(subtitleConfiguration.selectionFlags)
.setRoleFlags(subtitleConfiguration.roleFlags) .setRoleFlags(subtitleConfiguration.roleFlags)
.setLabel(subtitleConfiguration.label) .setLabel(subtitleConfiguration.label)
.setId(subtitleConfiguration.id)
.build(); .build();
dataSpec = dataSpec =
new DataSpec.Builder() new DataSpec.Builder()