diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 7aa5f2710b..51580c032c 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -169,6 +169,10 @@ a fallback value. * Remove `(Simple)ExoPlayer.setThrowsWhenUsingWrongThread`. Opting out of the thread enforcement is no longer possible. +* Change the following `IntDefs` to `@Target(TYPE_USE)` only. This may break + the compilation of usages in Kotlin, which can be fixed by moving the + annotation to annotate the type (`Int`). + * `@C.SelectionReason` ### 2.16.1 (2021-11-18) diff --git a/library/common/src/main/java/com/google/android/exoplayer2/C.java b/library/common/src/main/java/com/google/android/exoplayer2/C.java index 0876cfc0e6..ecc3f9c48b 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/C.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/C.java @@ -729,6 +729,7 @@ public final class C { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target(TYPE_USE) @IntDef( open = true, value = { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/MediaLoadData.java b/library/core/src/main/java/com/google/android/exoplayer2/source/MediaLoadData.java index 862b8ca6c0..5161c29d60 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/MediaLoadData.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/MediaLoadData.java @@ -41,7 +41,7 @@ public final class MediaLoadData { * One of the {@link SelectionReason selection reasons} if the data belongs to a track. {@link * C#SELECTION_REASON_UNKNOWN} otherwise. */ - public final int trackSelectionReason; + public final @C.SelectionReason int trackSelectionReason; /** * Optional data associated with the selection of the track to which the data belongs. Null if the * data does not belong to a track. diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/MergingMediaPeriod.java b/library/core/src/main/java/com/google/android/exoplayer2/source/MergingMediaPeriod.java index 0408fbbbf4..7fd4273a7c 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/MergingMediaPeriod.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/MergingMediaPeriod.java @@ -546,7 +546,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; } @Override - public int getSelectionReason() { + public @C.SelectionReason int getSelectionReason() { return trackSelection.getSelectionReason(); } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelection.java b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelection.java index 5c95b0c320..c09fb930b0 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelection.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelection.java @@ -313,7 +313,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection { private float playbackSpeed; private int selectedIndex; - private int reason; + private @C.SelectionReason int reason; private long lastBufferEvaluationMs; @Nullable private MediaChunk lastBufferEvaluationMediaChunk; @@ -446,7 +446,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection { } int previousSelectedIndex = selectedIndex; - int previousReason = reason; + @C.SelectionReason int previousReason = reason; int formatIndexOfPreviousChunk = queue.isEmpty() ? C.INDEX_UNSET : indexOf(Iterables.getLast(queue).trackFormat); if (formatIndexOfPreviousChunk != C.INDEX_UNSET) { @@ -484,7 +484,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection { } @Override - public int getSelectionReason() { + public @C.SelectionReason int getSelectionReason() { return reason; } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/ExoTrackSelection.java b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/ExoTrackSelection.java index 6f2772fb81..34ece16fcd 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/ExoTrackSelection.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/ExoTrackSelection.java @@ -122,6 +122,7 @@ public interface ExoTrackSelection extends TrackSelection { int getSelectedIndex(); /** Returns the reason for the current track selection. */ + @C.SelectionReason int getSelectionReason(); /** Returns optional data associated with the current track selection. */ diff --git a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/FixedTrackSelection.java b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/FixedTrackSelection.java index df198f6fe0..178fba1960 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/FixedTrackSelection.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/FixedTrackSelection.java @@ -25,7 +25,7 @@ import java.util.List; /** A {@link TrackSelection} consisting of a single track. */ public final class FixedTrackSelection extends BaseTrackSelection { - private final int reason; + private final @C.SelectionReason int reason; @Nullable private final Object data; /** @@ -53,7 +53,11 @@ public final class FixedTrackSelection extends BaseTrackSelection { * @param data Optional data associated with the track selection. */ public FixedTrackSelection( - TrackGroup group, int track, @Type int type, int reason, @Nullable Object data) { + TrackGroup group, + int track, + @Type int type, + @C.SelectionReason int reason, + @Nullable Object data) { super(group, /* tracks= */ new int[] {track}, type); this.reason = reason; this.data = data; @@ -75,7 +79,7 @@ public final class FixedTrackSelection extends BaseTrackSelection { } @Override - public int getSelectionReason() { + public @C.SelectionReason int getSelectionReason() { return reason; } diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java index 9d9943b312..e02383463b 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java @@ -915,7 +915,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; } @Override - public int getSelectionReason() { + public @C.SelectionReason int getSelectionReason() { return C.SELECTION_REASON_UNKNOWN; } diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeTrackSelection.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeTrackSelection.java index 3902b555a9..0fd89caf53 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeTrackSelection.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeTrackSelection.java @@ -114,7 +114,7 @@ public final class FakeTrackSelection implements ExoTrackSelection { } @Override - public int getSelectionReason() { + public @C.SelectionReason int getSelectionReason() { return C.SELECTION_REASON_UNKNOWN; } diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/MediaPeriodAsserts.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/MediaPeriodAsserts.java index cbb72a9557..fe7fa7acd2 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/MediaPeriodAsserts.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/MediaPeriodAsserts.java @@ -238,7 +238,7 @@ public final class MediaPeriodAsserts { } @Override - public int getSelectionReason() { + public @C.SelectionReason int getSelectionReason() { return C.SELECTION_REASON_UNKNOWN; }