From b8769b2717d62ccf677a05893945a0087e0228a3 Mon Sep 17 00:00:00 2001 From: ibaker Date: Wed, 25 May 2022 16:28:21 +0000 Subject: [PATCH] Fix some inconsistencies in the `MediaItem` API * Rename (via deprecation) `MediaItem.DrmConfiguration.Builder#forceSessionsForAudioAndVideoTracks` to `setForceSessionsForAudioAndVideoTracks`. This is more consistent with existing 'force' method names both in this class and in `TrackSelectionParameters.Builder`. * Add missing `@Nullable` annotation to the parameter for `MediaItem.SubtitleConfiguration.Builder#setMimeType`. This annotation is already present on the `MediaItem.SubtitleConfiguration#mimeType` field that this setter corresponds to. PiperOrigin-RevId: 450941336 --- .../android/exoplayer2/demo/IntentUtil.java | 2 +- .../demo/SampleChooserActivity.java | 2 +- .../google/android/exoplayer2/MediaItem.java | 29 ++++++++++++++----- .../android/exoplayer2/MediaItemTest.java | 2 +- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/IntentUtil.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/IntentUtil.java index 93637ce271..bb32f0c680 100644 --- a/demos/main/src/main/java/com/google/android/exoplayer2/demo/IntentUtil.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/IntentUtil.java @@ -189,7 +189,7 @@ public class IntentUtil { intent.getBooleanExtra( DRM_FORCE_DEFAULT_LICENSE_URI_EXTRA + extrasKeySuffix, false)) .setLicenseRequestHeaders(headers) - .forceSessionsForAudioAndVideoTracks( + .setForceSessionsForAudioAndVideoTracks( intent.getBooleanExtra(DRM_SESSION_FOR_CLEAR_CONTENT + extrasKeySuffix, false)) .build()); } diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java index 44f20f0e04..e47c273455 100644 --- a/demos/main/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java @@ -455,7 +455,7 @@ public class SampleChooserActivity extends AppCompatActivity new MediaItem.DrmConfiguration.Builder(drmUuid) .setLicenseUri(drmLicenseUri) .setLicenseRequestHeaders(drmLicenseRequestHeaders) - .forceSessionsForAudioAndVideoTracks(drmSessionForClearContent) + .setForceSessionsForAudioAndVideoTracks(drmSessionForClearContent) .setMultiSession(drmMultiSession) .setForceDefaultLicenseUri(drmForceDefaultLicenseUri) .build()); 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 44de3a254e..6e90fa6349 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 @@ -29,6 +29,7 @@ import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Util; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.errorprone.annotations.InlineMe; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -303,11 +304,11 @@ public final class MediaItem implements Bundleable { /** * @deprecated Use {@link #setDrmConfiguration(DrmConfiguration)} and {@link - * DrmConfiguration.Builder#forceSessionsForAudioAndVideoTracks(boolean)} instead. + * DrmConfiguration.Builder#setForceSessionsForAudioAndVideoTracks(boolean)} instead. */ @Deprecated public Builder setDrmSessionForClearPeriods(boolean sessionForClearPeriods) { - drmConfiguration.forceSessionsForAudioAndVideoTracks(sessionForClearPeriods); + drmConfiguration.setForceSessionsForAudioAndVideoTracks(sessionForClearPeriods); return this; } @@ -633,6 +634,18 @@ public final class MediaItem implements Bundleable { return this; } + /** + * @deprecated Use {@link #setForceSessionsForAudioAndVideoTracks(boolean)} instead. + */ + @Deprecated + @InlineMe( + replacement = + "this.setForceSessionsForAudioAndVideoTracks(forceSessionsForAudioAndVideoTracks)") + public Builder forceSessionsForAudioAndVideoTracks( + boolean forceSessionsForAudioAndVideoTracks) { + return setForceSessionsForAudioAndVideoTracks(forceSessionsForAudioAndVideoTracks); + } + /** * Sets whether a DRM session should be used for clear tracks of type {@link * C#TRACK_TYPE_VIDEO} and {@link C#TRACK_TYPE_AUDIO}. @@ -640,10 +653,10 @@ public final class MediaItem implements Bundleable { *

This method overrides what has been set by previously calling {@link * #setForcedSessionTrackTypes(List)}. */ - public Builder forceSessionsForAudioAndVideoTracks( - boolean useClearSessionsForAudioAndVideoTracks) { + public Builder setForceSessionsForAudioAndVideoTracks( + boolean forceSessionsForAudioAndVideoTracks) { this.setForcedSessionTrackTypes( - useClearSessionsForAudioAndVideoTracks + forceSessionsForAudioAndVideoTracks ? ImmutableList.of(C.TRACK_TYPE_VIDEO, C.TRACK_TYPE_AUDIO) : ImmutableList.of()); return this; @@ -654,10 +667,10 @@ public final class MediaItem implements Bundleable { * when the tracks are in the clear. * *

For the common case of using a DRM session for {@link C#TRACK_TYPE_VIDEO} and {@link - * C#TRACK_TYPE_AUDIO}, {@link #forceSessionsForAudioAndVideoTracks(boolean)} can be used. + * C#TRACK_TYPE_AUDIO}, {@link #setForceSessionsForAudioAndVideoTracks(boolean)} can be used. * *

This method overrides what has been set by previously calling {@link - * #forceSessionsForAudioAndVideoTracks(boolean)}. + * #setForceSessionsForAudioAndVideoTracks(boolean)}. */ public Builder setForcedSessionTrackTypes( List<@C.TrackType Integer> forcedSessionTrackTypes) { @@ -1281,7 +1294,7 @@ public final class MediaItem implements Bundleable { } /** Sets the MIME type. */ - public Builder setMimeType(String mimeType) { + public Builder setMimeType(@Nullable String mimeType) { this.mimeType = mimeType; return this; } 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 457162d744..2b57645f54 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 @@ -225,7 +225,7 @@ public class MediaItemTest { new MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID) .setLicenseUri(licenseUri) .setForcedSessionTrackTypes(ImmutableList.of(C.TRACK_TYPE_AUDIO)) - .forceSessionsForAudioAndVideoTracks(true) + .setForceSessionsForAudioAndVideoTracks(true) .build(); assertThat(drmConfiguration.sessionForClearTypes)