diff --git a/library/common/src/main/java/com/google/android/exoplayer2/trackselection/TrackSelection.java b/library/common/src/main/java/com/google/android/exoplayer2/trackselection/TrackSelection.java index e439b5d00e..6ba2687326 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/trackselection/TrackSelection.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/trackselection/TrackSelection.java @@ -15,9 +15,15 @@ */ package com.google.android.exoplayer2.trackselection; +import androidx.annotation.IntDef; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.source.TrackGroup; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; /** * A track selection consisting of a static subset of selected tracks belonging to a {@link @@ -27,6 +33,17 @@ import com.google.android.exoplayer2.source.TrackGroup; */ public interface TrackSelection { + /** + * Represents a type track selection. Either {@link #TYPE_UNSET} or an app-defined value (see + * {@link #TYPE_CUSTOM_BASE}). + */ + @Documented + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE_USE}) + @IntDef( + open = true, + value = {TYPE_UNSET}) + @interface Type {} /** An unspecified track selection type. */ int TYPE_UNSET = 0; /** The first value that can be used for application specific track selection types. */ @@ -40,6 +57,7 @@ public interface TrackSelection { * starting from {@link #TYPE_CUSTOM_BASE} to ensure they don't conflict with any types that may * be added to the library in the future. */ + @Type int getType(); /** Returns the {@link TrackGroup} to which the selected tracks belong. */ 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 95df027ac2..73fa081a86 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 @@ -273,7 +273,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection { protected AdaptiveTrackSelection( TrackGroup group, int[] tracks, - int type, + @Type int type, BandwidthMeter bandwidthMeter, long minDurationForQualityIncreaseMs, long maxDurationForQualityDecreaseMs, diff --git a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/BaseTrackSelection.java b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/BaseTrackSelection.java index 670f319f90..d0ddf18b8f 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/BaseTrackSelection.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/BaseTrackSelection.java @@ -39,7 +39,7 @@ public abstract class BaseTrackSelection implements ExoTrackSelection { protected final int[] tracks; /** The type of the selection. */ - private final int type; + private final @Type int type; /** The {@link Format}s of the selected tracks, in order of decreasing bandwidth. */ private final Format[] formats; /** Selected track exclusion timestamps, in order of decreasing bandwidth. */ @@ -63,7 +63,7 @@ public abstract class BaseTrackSelection implements ExoTrackSelection { * null or empty. May be in any order. * @param type The type that will be returned from {@link TrackSelection#getType()}. */ - public BaseTrackSelection(TrackGroup group, int[] tracks, int type) { + public BaseTrackSelection(TrackGroup group, int[] tracks, @Type int type) { Assertions.checkState(tracks.length > 0); this.type = type; this.group = Assertions.checkNotNull(group); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java index 19fd32187f..fc9e188e16 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java @@ -1262,7 +1262,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { public final int groupIndex; public final int[] tracks; public final int length; - public final int type; + public final @TrackSelection.Type int type; /** * Constructs a {@code SelectionOverride} to override tracks of a group. @@ -1281,7 +1281,7 @@ public class DefaultTrackSelector extends MappingTrackSelector { * @param tracks The overriding track indices within the track group. * @param type The type that will be returned from {@link TrackSelection#getType()}. */ - public SelectionOverride(int groupIndex, int[] tracks, int type) { + public SelectionOverride(int groupIndex, int[] tracks, @TrackSelection.Type int type) { this.groupIndex = groupIndex; this.tracks = Arrays.copyOf(tracks, tracks.length); this.length = tracks.length; 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 ca4445362d..6f2772fb81 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 @@ -43,7 +43,7 @@ public interface ExoTrackSelection extends TrackSelection { /** The indices of the selected tracks in {@link #group}. */ public final int[] tracks; /** The type that will be returned from {@link TrackSelection#getType()}. */ - public final int type; + public final @Type int type; /** * @param group The {@link TrackGroup}. Must not be null. @@ -60,7 +60,7 @@ public interface ExoTrackSelection extends TrackSelection { * null or empty. May be in any order. * @param type The type that will be returned from {@link TrackSelection#getType()}. */ - public Definition(TrackGroup group, int[] tracks, int type) { + public Definition(TrackGroup group, int[] tracks, @Type int type) { this.group = group; this.tracks = tracks; this.type = type; 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 7995526408..df198f6fe0 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 @@ -41,13 +41,8 @@ public final class FixedTrackSelection extends BaseTrackSelection { * @param track The index of the selected track within the {@link TrackGroup}. * @param type The type that will be returned from {@link TrackSelection#getType()}. */ - public FixedTrackSelection(TrackGroup group, int track, int type) { - this( - group, - /* track= */ track, - /* type= */ type, - /* reason= */ C.SELECTION_REASON_UNKNOWN, - null); + public FixedTrackSelection(TrackGroup group, int track, @Type int type) { + this(group, track, type, C.SELECTION_REASON_UNKNOWN, /* data= */ null); } /** @@ -58,8 +53,8 @@ public final class FixedTrackSelection extends BaseTrackSelection { * @param data Optional data associated with the track selection. */ public FixedTrackSelection( - TrackGroup group, int track, int type, int reason, @Nullable Object data) { - super(group, /* tracks= */ new int[] {track}, /* type= */ type); + TrackGroup group, int track, @Type int type, int reason, @Nullable Object data) { + super(group, /* tracks= */ new int[] {track}, type); this.reason = reason; this.data = data; }