|
46 | 46 | import androidx.media3.common.VideoSize;
|
47 | 47 | import androidx.media3.common.text.CueGroup;
|
48 | 48 | import androidx.media3.common.util.Assertions;
|
| 49 | +import androidx.media3.common.util.UnstableApi; |
| 50 | +import com.google.common.base.Objects; |
49 | 51 | import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
50 | 52 | import java.lang.annotation.Documented;
|
51 | 53 | import java.lang.annotation.Retention;
|
|
58 | 60 | */
|
59 | 61 | /* package */ class PlayerInfo implements Bundleable {
|
60 | 62 |
|
| 63 | + /** |
| 64 | + * Holds information about what properties of the {@link PlayerInfo} have been excluded when sent |
| 65 | + * to the controller. |
| 66 | + */ |
| 67 | + public static class BundlingExclusions implements Bundleable { |
| 68 | + |
| 69 | + /** Whether the {@linkplain PlayerInfo#timeline timeline} is excluded. */ |
| 70 | + public final boolean isTimelineExcluded; |
| 71 | + /** Whether the {@linkplain PlayerInfo#currentTracks current tracks} are excluded. */ |
| 72 | + public final boolean areCurrentTracksExcluded; |
| 73 | + |
| 74 | + /** Creates a new instance. */ |
| 75 | + public BundlingExclusions(boolean isTimelineExcluded, boolean areCurrentTracksExcluded) { |
| 76 | + this.isTimelineExcluded = isTimelineExcluded; |
| 77 | + this.areCurrentTracksExcluded = areCurrentTracksExcluded; |
| 78 | + } |
| 79 | + |
| 80 | + // Bundleable implementation. |
| 81 | + |
| 82 | + @Documented |
| 83 | + @Retention(RetentionPolicy.SOURCE) |
| 84 | + @Target(TYPE_USE) |
| 85 | + @IntDef({FIELD_IS_TIMELINE_EXCLUDED, FIELD_ARE_CURRENT_TRACKS_EXCLUDED}) |
| 86 | + private @interface FieldNumber {} |
| 87 | + |
| 88 | + private static final int FIELD_IS_TIMELINE_EXCLUDED = 0; |
| 89 | + private static final int FIELD_ARE_CURRENT_TRACKS_EXCLUDED = 1; |
| 90 | + // Next field key = 2 |
| 91 | + |
| 92 | + @UnstableApi |
| 93 | + @Override |
| 94 | + public Bundle toBundle() { |
| 95 | + Bundle bundle = new Bundle(); |
| 96 | + bundle.putBoolean(keyForField(FIELD_IS_TIMELINE_EXCLUDED), isTimelineExcluded); |
| 97 | + bundle.putBoolean(keyForField(FIELD_ARE_CURRENT_TRACKS_EXCLUDED), areCurrentTracksExcluded); |
| 98 | + return bundle; |
| 99 | + } |
| 100 | + |
| 101 | + public static final Creator<BundlingExclusions> CREATOR = |
| 102 | + bundle -> |
| 103 | + new BundlingExclusions( |
| 104 | + bundle.getBoolean( |
| 105 | + keyForField(FIELD_IS_TIMELINE_EXCLUDED), /* defaultValue= */ false), |
| 106 | + bundle.getBoolean( |
| 107 | + keyForField(FIELD_ARE_CURRENT_TRACKS_EXCLUDED), /* defaultValue= */ false)); |
| 108 | + |
| 109 | + private static String keyForField(@BundlingExclusions.FieldNumber int field) { |
| 110 | + return Integer.toString(field, Character.MAX_RADIX); |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public boolean equals(@Nullable Object o) { |
| 115 | + if (this == o) { |
| 116 | + return true; |
| 117 | + } |
| 118 | + if (!(o instanceof BundlingExclusions)) { |
| 119 | + return false; |
| 120 | + } |
| 121 | + BundlingExclusions that = (BundlingExclusions) o; |
| 122 | + return isTimelineExcluded == that.isTimelineExcluded |
| 123 | + && areCurrentTracksExcluded == that.areCurrentTracksExcluded; |
| 124 | + } |
| 125 | + |
| 126 | + @Override |
| 127 | + public int hashCode() { |
| 128 | + return Objects.hashCode(isTimelineExcluded, areCurrentTracksExcluded); |
| 129 | + } |
| 130 | + } |
| 131 | + |
61 | 132 | public static class Builder {
|
62 | 133 |
|
63 | 134 | @Nullable private PlaybackException playerError;
|
@@ -983,7 +1054,7 @@ private static PlayerInfo fromBundle(Bundle bundle) {
|
983 | 1054 | trackSelectionParameters);
|
984 | 1055 | }
|
985 | 1056 |
|
986 |
| - private static String keyForField(@FieldNumber int field) { |
| 1057 | + private static String keyForField(@PlayerInfo.FieldNumber int field) { |
987 | 1058 | return Integer.toString(field, Character.MAX_RADIX);
|
988 | 1059 | }
|
989 | 1060 | }
|
0 commit comments