mirror of
https://github.com/androidx/media.git
synced 2025-05-08 16:10:38 +08:00
Tracks.Group/TrackGroup variable naming disambiguation
PiperOrigin-RevId: 441712166
This commit is contained in:
parent
29e32540de
commit
d9f0c2c071
@ -35,8 +35,8 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An immutable group of tracks. All tracks in a group present the same content, but their formats
|
* An immutable group of tracks available within a media stream. All tracks in a group present the
|
||||||
* may differ.
|
* same content, but their formats may differ.
|
||||||
*
|
*
|
||||||
* <p>As an example of how tracks can be grouped, consider an adaptive playback where a main video
|
* <p>As an example of how tracks can be grouped, consider an adaptive playback where a main video
|
||||||
* feed is provided in five resolutions, and an alternative video feed (e.g., a different camera
|
* feed is provided in five resolutions, and an alternative video feed (e.g., a different camera
|
||||||
@ -48,6 +48,10 @@ import java.util.List;
|
|||||||
* languages is not considered to be the same. Conversely, audio tracks in the same language that
|
* languages is not considered to be the same. Conversely, audio tracks in the same language that
|
||||||
* only differ in properties such as bitrate, sampling rate, channel count and so on can be grouped.
|
* only differ in properties such as bitrate, sampling rate, channel count and so on can be grouped.
|
||||||
* This also applies to text tracks.
|
* This also applies to text tracks.
|
||||||
|
*
|
||||||
|
* <p>Note also that this class only contains information derived from the media itself. Unlike
|
||||||
|
* {@link Tracks.Group}, it does not include runtime information such as the extent to which
|
||||||
|
* playback of each track is supported by the device, or which tracks are currently selected.
|
||||||
*/
|
*/
|
||||||
public final class TrackGroup implements Bundleable {
|
public final class TrackGroup implements Bundleable {
|
||||||
|
|
||||||
|
@ -49,8 +49,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public final class TrackSelectionOverride implements Bundleable {
|
public final class TrackSelectionOverride implements Bundleable {
|
||||||
|
|
||||||
/** The {@link TrackGroup} whose {@link #trackIndices} are forced to be selected. */
|
/** The media {@link TrackGroup} whose {@link #trackIndices} are forced to be selected. */
|
||||||
public final TrackGroup trackGroup;
|
public final TrackGroup mediaTrackGroup;
|
||||||
/** The indices of tracks in a {@link TrackGroup} to be selected. */
|
/** The indices of tracks in a {@link TrackGroup} to be selected. */
|
||||||
public final ImmutableList<Integer> trackIndices;
|
public final ImmutableList<Integer> trackIndices;
|
||||||
|
|
||||||
@ -68,32 +68,32 @@ public final class TrackSelectionOverride implements Bundleable {
|
|||||||
/**
|
/**
|
||||||
* Constructs an instance to force {@code trackIndex} in {@code trackGroup} to be selected.
|
* Constructs an instance to force {@code trackIndex} in {@code trackGroup} to be selected.
|
||||||
*
|
*
|
||||||
* @param trackGroup The {@link TrackGroup} for which to override the track selection.
|
* @param mediaTrackGroup The media {@link TrackGroup} for which to override the track selection.
|
||||||
* @param trackIndex The index of the track in the {@link TrackGroup} to select.
|
* @param trackIndex The index of the track in the {@link TrackGroup} to select.
|
||||||
*/
|
*/
|
||||||
public TrackSelectionOverride(TrackGroup trackGroup, int trackIndex) {
|
public TrackSelectionOverride(TrackGroup mediaTrackGroup, int trackIndex) {
|
||||||
this(trackGroup, ImmutableList.of(trackIndex));
|
this(mediaTrackGroup, ImmutableList.of(trackIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance to force {@code trackIndices} in {@code trackGroup} to be selected.
|
* Constructs an instance to force {@code trackIndices} in {@code trackGroup} to be selected.
|
||||||
*
|
*
|
||||||
* @param trackGroup The {@link TrackGroup} for which to override the track selection.
|
* @param mediaTrackGroup The media {@link TrackGroup} for which to override the track selection.
|
||||||
* @param trackIndices The indices of the tracks in the {@link TrackGroup} to select.
|
* @param trackIndices The indices of the tracks in the {@link TrackGroup} to select.
|
||||||
*/
|
*/
|
||||||
public TrackSelectionOverride(TrackGroup trackGroup, List<Integer> trackIndices) {
|
public TrackSelectionOverride(TrackGroup mediaTrackGroup, List<Integer> trackIndices) {
|
||||||
if (!trackIndices.isEmpty()) {
|
if (!trackIndices.isEmpty()) {
|
||||||
if (min(trackIndices) < 0 || max(trackIndices) >= trackGroup.length) {
|
if (min(trackIndices) < 0 || max(trackIndices) >= mediaTrackGroup.length) {
|
||||||
throw new IndexOutOfBoundsException();
|
throw new IndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.trackGroup = trackGroup;
|
this.mediaTrackGroup = mediaTrackGroup;
|
||||||
this.trackIndices = ImmutableList.copyOf(trackIndices);
|
this.trackIndices = ImmutableList.copyOf(trackIndices);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the {@link C.TrackType} of the overridden track group. */
|
/** Returns the {@link C.TrackType} of the overridden track group. */
|
||||||
public @C.TrackType int getType() {
|
public @C.TrackType int getType() {
|
||||||
return trackGroup.type;
|
return mediaTrackGroup.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -105,12 +105,12 @@ public final class TrackSelectionOverride implements Bundleable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TrackSelectionOverride that = (TrackSelectionOverride) obj;
|
TrackSelectionOverride that = (TrackSelectionOverride) obj;
|
||||||
return trackGroup.equals(that.trackGroup) && trackIndices.equals(that.trackIndices);
|
return mediaTrackGroup.equals(that.mediaTrackGroup) && trackIndices.equals(that.trackIndices);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return trackGroup.hashCode() + 31 * trackIndices.hashCode();
|
return mediaTrackGroup.hashCode() + 31 * trackIndices.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bundleable implementation
|
// Bundleable implementation
|
||||||
@ -119,7 +119,7 @@ public final class TrackSelectionOverride implements Bundleable {
|
|||||||
@Override
|
@Override
|
||||||
public Bundle toBundle() {
|
public Bundle toBundle() {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putBundle(keyForField(FIELD_TRACK_GROUP), trackGroup.toBundle());
|
bundle.putBundle(keyForField(FIELD_TRACK_GROUP), mediaTrackGroup.toBundle());
|
||||||
bundle.putIntArray(keyForField(FIELD_TRACKS), Ints.toArray(trackIndices));
|
bundle.putIntArray(keyForField(FIELD_TRACKS), Ints.toArray(trackIndices));
|
||||||
return bundle;
|
return bundle;
|
||||||
}
|
}
|
||||||
@ -129,9 +129,9 @@ public final class TrackSelectionOverride implements Bundleable {
|
|||||||
public static final Creator<TrackSelectionOverride> CREATOR =
|
public static final Creator<TrackSelectionOverride> CREATOR =
|
||||||
bundle -> {
|
bundle -> {
|
||||||
Bundle trackGroupBundle = checkNotNull(bundle.getBundle(keyForField(FIELD_TRACK_GROUP)));
|
Bundle trackGroupBundle = checkNotNull(bundle.getBundle(keyForField(FIELD_TRACK_GROUP)));
|
||||||
TrackGroup trackGroup = TrackGroup.CREATOR.fromBundle(trackGroupBundle);
|
TrackGroup mediaTrackGroup = TrackGroup.CREATOR.fromBundle(trackGroupBundle);
|
||||||
int[] tracks = checkNotNull(bundle.getIntArray(keyForField(FIELD_TRACKS)));
|
int[] tracks = checkNotNull(bundle.getIntArray(keyForField(FIELD_TRACKS)));
|
||||||
return new TrackSelectionOverride(trackGroup, Ints.asList(tracks));
|
return new TrackSelectionOverride(mediaTrackGroup, Ints.asList(tracks));
|
||||||
};
|
};
|
||||||
|
|
||||||
private static String keyForField(@FieldNumber int field) {
|
private static String keyForField(@FieldNumber int field) {
|
||||||
|
@ -255,7 +255,7 @@ public class TrackSelectionParameters implements Bundleable {
|
|||||||
overrides = new HashMap<>();
|
overrides = new HashMap<>();
|
||||||
for (int i = 0; i < overrideList.size(); i++) {
|
for (int i = 0; i < overrideList.size(); i++) {
|
||||||
TrackSelectionOverride override = overrideList.get(i);
|
TrackSelectionOverride override = overrideList.get(i);
|
||||||
overrides.put(override.trackGroup, override);
|
overrides.put(override.mediaTrackGroup, override);
|
||||||
}
|
}
|
||||||
int[] disabledTrackTypeArray =
|
int[] disabledTrackTypeArray =
|
||||||
firstNonNull(bundle.getIntArray(keyForField(FIELD_DISABLED_TRACK_TYPE)), new int[0]);
|
firstNonNull(bundle.getIntArray(keyForField(FIELD_DISABLED_TRACK_TYPE)), new int[0]);
|
||||||
@ -678,20 +678,20 @@ public class TrackSelectionParameters implements Bundleable {
|
|||||||
|
|
||||||
/** Adds an override, replacing any override for the same {@link TrackGroup}. */
|
/** Adds an override, replacing any override for the same {@link TrackGroup}. */
|
||||||
public Builder addOverride(TrackSelectionOverride override) {
|
public Builder addOverride(TrackSelectionOverride override) {
|
||||||
overrides.put(override.trackGroup, override);
|
overrides.put(override.mediaTrackGroup, override);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets an override, replacing all existing overrides with the same track type. */
|
/** Sets an override, replacing all existing overrides with the same track type. */
|
||||||
public Builder setOverrideForType(TrackSelectionOverride override) {
|
public Builder setOverrideForType(TrackSelectionOverride override) {
|
||||||
clearOverridesOfType(override.getType());
|
clearOverridesOfType(override.getType());
|
||||||
overrides.put(override.trackGroup, override);
|
overrides.put(override.mediaTrackGroup, override);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Removes the override for the provided {@link TrackGroup}, if there is one. */
|
/** Removes the override for the provided media {@link TrackGroup}, if there is one. */
|
||||||
public Builder clearOverride(TrackGroup trackGroup) {
|
public Builder clearOverride(TrackGroup mediaTrackGroup) {
|
||||||
overrides.remove(trackGroup);
|
overrides.remove(mediaTrackGroup);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public final class Tracks implements Bundleable {
|
|||||||
/** The number of tracks in the group. */
|
/** The number of tracks in the group. */
|
||||||
public final int length;
|
public final int length;
|
||||||
|
|
||||||
private final TrackGroup trackGroup;
|
private final TrackGroup mediaTrackGroup;
|
||||||
private final boolean adaptiveSupported;
|
private final boolean adaptiveSupported;
|
||||||
private final @C.FormatSupport int[] trackSupport;
|
private final @C.FormatSupport int[] trackSupport;
|
||||||
private final boolean[] trackSelected;
|
private final boolean[] trackSelected;
|
||||||
@ -57,7 +57,7 @@ public final class Tracks implements Bundleable {
|
|||||||
/**
|
/**
|
||||||
* Constructs an instance.
|
* Constructs an instance.
|
||||||
*
|
*
|
||||||
* @param trackGroup The underlying {@link TrackGroup}.
|
* @param mediaTrackGroup The underlying {@link TrackGroup} defined by the media.
|
||||||
* @param adaptiveSupported Whether the player supports adaptive selections containing more than
|
* @param adaptiveSupported Whether the player supports adaptive selections containing more than
|
||||||
* one track in the group.
|
* one track in the group.
|
||||||
* @param trackSupport The {@link C.FormatSupport} of each track in the group.
|
* @param trackSupport The {@link C.FormatSupport} of each track in the group.
|
||||||
@ -65,21 +65,28 @@ public final class Tracks implements Bundleable {
|
|||||||
*/
|
*/
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public Group(
|
public Group(
|
||||||
TrackGroup trackGroup,
|
TrackGroup mediaTrackGroup,
|
||||||
boolean adaptiveSupported,
|
boolean adaptiveSupported,
|
||||||
@C.FormatSupport int[] trackSupport,
|
@C.FormatSupport int[] trackSupport,
|
||||||
boolean[] trackSelected) {
|
boolean[] trackSelected) {
|
||||||
length = trackGroup.length;
|
length = mediaTrackGroup.length;
|
||||||
checkArgument(length == trackSupport.length && length == trackSelected.length);
|
checkArgument(length == trackSupport.length && length == trackSelected.length);
|
||||||
this.trackGroup = trackGroup;
|
this.mediaTrackGroup = mediaTrackGroup;
|
||||||
this.adaptiveSupported = adaptiveSupported && length > 1;
|
this.adaptiveSupported = adaptiveSupported && length > 1;
|
||||||
this.trackSupport = trackSupport.clone();
|
this.trackSupport = trackSupport.clone();
|
||||||
this.trackSelected = trackSelected.clone();
|
this.trackSelected = trackSelected.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the underlying {@link TrackGroup}. */
|
/**
|
||||||
public TrackGroup getTrackGroup() {
|
* Returns the underlying {@link TrackGroup} defined by the media.
|
||||||
return trackGroup;
|
*
|
||||||
|
* <p>Unlike this class, {@link TrackGroup} only contains information defined by the media
|
||||||
|
* itself, and does not contain runtime information such as which tracks are supported and
|
||||||
|
* currently selected. This makes it suitable for use as a {@code key} in certain {@code (key,
|
||||||
|
* value)} data structures.
|
||||||
|
*/
|
||||||
|
public TrackGroup getMediaTrackGroup() {
|
||||||
|
return mediaTrackGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,7 +96,7 @@ public final class Tracks implements Bundleable {
|
|||||||
* @return The {@link Format} of the track.
|
* @return The {@link Format} of the track.
|
||||||
*/
|
*/
|
||||||
public Format getTrackFormat(int trackIndex) {
|
public Format getTrackFormat(int trackIndex) {
|
||||||
return trackGroup.getFormat(trackIndex);
|
return mediaTrackGroup.getFormat(trackIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -187,7 +194,7 @@ public final class Tracks implements Bundleable {
|
|||||||
|
|
||||||
/** Returns the {@link C.TrackType} of the group. */
|
/** Returns the {@link C.TrackType} of the group. */
|
||||||
public @C.TrackType int getType() {
|
public @C.TrackType int getType() {
|
||||||
return trackGroup.type;
|
return mediaTrackGroup.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -200,14 +207,14 @@ public final class Tracks implements Bundleable {
|
|||||||
}
|
}
|
||||||
Group that = (Group) other;
|
Group that = (Group) other;
|
||||||
return adaptiveSupported == that.adaptiveSupported
|
return adaptiveSupported == that.adaptiveSupported
|
||||||
&& trackGroup.equals(that.trackGroup)
|
&& mediaTrackGroup.equals(that.mediaTrackGroup)
|
||||||
&& Arrays.equals(trackSupport, that.trackSupport)
|
&& Arrays.equals(trackSupport, that.trackSupport)
|
||||||
&& Arrays.equals(trackSelected, that.trackSelected);
|
&& Arrays.equals(trackSelected, that.trackSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = trackGroup.hashCode();
|
int result = mediaTrackGroup.hashCode();
|
||||||
result = 31 * result + (adaptiveSupported ? 1 : 0);
|
result = 31 * result + (adaptiveSupported ? 1 : 0);
|
||||||
result = 31 * result + Arrays.hashCode(trackSupport);
|
result = 31 * result + Arrays.hashCode(trackSupport);
|
||||||
result = 31 * result + Arrays.hashCode(trackSelected);
|
result = 31 * result + Arrays.hashCode(trackSelected);
|
||||||
@ -234,7 +241,7 @@ public final class Tracks implements Bundleable {
|
|||||||
@Override
|
@Override
|
||||||
public Bundle toBundle() {
|
public Bundle toBundle() {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putBundle(keyForField(FIELD_TRACK_GROUP), trackGroup.toBundle());
|
bundle.putBundle(keyForField(FIELD_TRACK_GROUP), mediaTrackGroup.toBundle());
|
||||||
bundle.putIntArray(keyForField(FIELD_TRACK_SUPPORT), trackSupport);
|
bundle.putIntArray(keyForField(FIELD_TRACK_SUPPORT), trackSupport);
|
||||||
bundle.putBooleanArray(keyForField(FIELD_TRACK_SELECTED), trackSelected);
|
bundle.putBooleanArray(keyForField(FIELD_TRACK_SELECTED), trackSelected);
|
||||||
bundle.putBoolean(keyForField(FIELD_ADAPTIVE_SUPPORTED), adaptiveSupported);
|
bundle.putBoolean(keyForField(FIELD_ADAPTIVE_SUPPORTED), adaptiveSupported);
|
||||||
|
@ -33,7 +33,7 @@ public final class TrackSelectionOverrideTest {
|
|||||||
TrackSelectionOverride trackSelectionOverride =
|
TrackSelectionOverride trackSelectionOverride =
|
||||||
new TrackSelectionOverride(newTrackGroupWithIds(1, 2), /* trackIndex= */ 1);
|
new TrackSelectionOverride(newTrackGroupWithIds(1, 2), /* trackIndex= */ 1);
|
||||||
|
|
||||||
assertThat(trackSelectionOverride.trackGroup).isEqualTo(newTrackGroupWithIds(1, 2));
|
assertThat(trackSelectionOverride.mediaTrackGroup).isEqualTo(newTrackGroupWithIds(1, 2));
|
||||||
assertThat(trackSelectionOverride.trackIndices).containsExactly(1).inOrder();
|
assertThat(trackSelectionOverride.trackIndices).containsExactly(1).inOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ public final class TrackSelectionOverrideTest {
|
|||||||
TrackSelectionOverride trackSelectionOverride =
|
TrackSelectionOverride trackSelectionOverride =
|
||||||
new TrackSelectionOverride(newTrackGroupWithIds(1, 2), ImmutableList.of(1));
|
new TrackSelectionOverride(newTrackGroupWithIds(1, 2), ImmutableList.of(1));
|
||||||
|
|
||||||
assertThat(trackSelectionOverride.trackGroup).isEqualTo(newTrackGroupWithIds(1, 2));
|
assertThat(trackSelectionOverride.mediaTrackGroup).isEqualTo(newTrackGroupWithIds(1, 2));
|
||||||
assertThat(trackSelectionOverride.trackIndices).containsExactly(1);
|
assertThat(trackSelectionOverride.trackIndices).containsExactly(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ public final class TrackSelectionOverrideTest {
|
|||||||
TrackSelectionOverride trackSelectionOverride =
|
TrackSelectionOverride trackSelectionOverride =
|
||||||
new TrackSelectionOverride(newTrackGroupWithIds(1, 2), ImmutableList.of());
|
new TrackSelectionOverride(newTrackGroupWithIds(1, 2), ImmutableList.of());
|
||||||
|
|
||||||
assertThat(trackSelectionOverride.trackGroup).isEqualTo(newTrackGroupWithIds(1, 2));
|
assertThat(trackSelectionOverride.mediaTrackGroup).isEqualTo(newTrackGroupWithIds(1, 2));
|
||||||
assertThat(trackSelectionOverride.trackIndices).isEmpty();
|
assertThat(trackSelectionOverride.trackIndices).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,8 @@ public final class TrackSelectionParametersTest {
|
|||||||
assertThat(parameters.forceLowestBitrate).isFalse();
|
assertThat(parameters.forceLowestBitrate).isFalse();
|
||||||
assertThat(parameters.forceHighestSupportedBitrate).isTrue();
|
assertThat(parameters.forceHighestSupportedBitrate).isTrue();
|
||||||
assertThat(parameters.overrides)
|
assertThat(parameters.overrides)
|
||||||
.containsExactly(override1.trackGroup, override1, override2.trackGroup, override2);
|
.containsExactly(
|
||||||
|
override1.mediaTrackGroup, override1, override2.mediaTrackGroup, override2);
|
||||||
assertThat(parameters.disabledTrackTypes)
|
assertThat(parameters.disabledTrackTypes)
|
||||||
.containsExactly(C.TRACK_TYPE_AUDIO, C.TRACK_TYPE_TEXT);
|
.containsExactly(C.TRACK_TYPE_AUDIO, C.TRACK_TYPE_TEXT);
|
||||||
}
|
}
|
||||||
@ -203,7 +204,8 @@ public final class TrackSelectionParametersTest {
|
|||||||
TrackSelectionParameters.CREATOR.fromBundle(trackSelectionParameters.toBundle());
|
TrackSelectionParameters.CREATOR.fromBundle(trackSelectionParameters.toBundle());
|
||||||
|
|
||||||
assertThat(fromBundle).isEqualTo(trackSelectionParameters);
|
assertThat(fromBundle).isEqualTo(trackSelectionParameters);
|
||||||
assertThat(trackSelectionParameters.overrides).containsExactly(override.trackGroup, override);
|
assertThat(trackSelectionParameters.overrides)
|
||||||
|
.containsExactly(override.mediaTrackGroup, override);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -220,7 +222,8 @@ public final class TrackSelectionParametersTest {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
assertThat(trackSelectionParameters.overrides)
|
assertThat(trackSelectionParameters.overrides)
|
||||||
.containsExactly(override1.trackGroup, override1, override2.trackGroup, override2);
|
.containsExactly(
|
||||||
|
override1.mediaTrackGroup, override1, override2.mediaTrackGroup, override2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -237,7 +240,8 @@ public final class TrackSelectionParametersTest {
|
|||||||
.addOverride(override2)
|
.addOverride(override2)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
assertThat(trackSelectionParameters.overrides).containsExactly(override2.trackGroup, override2);
|
assertThat(trackSelectionParameters.overrides)
|
||||||
|
.containsExactly(override2.mediaTrackGroup, override2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -253,7 +257,8 @@ public final class TrackSelectionParametersTest {
|
|||||||
.setOverrideForType(override2)
|
.setOverrideForType(override2)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
assertThat(trackSelectionParameters.overrides).containsExactly(override2.trackGroup, override2);
|
assertThat(trackSelectionParameters.overrides)
|
||||||
|
.containsExactly(override2.mediaTrackGroup, override2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -269,7 +274,8 @@ public final class TrackSelectionParametersTest {
|
|||||||
.clearOverridesOfType(C.TRACK_TYPE_AUDIO)
|
.clearOverridesOfType(C.TRACK_TYPE_AUDIO)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
assertThat(trackSelectionParameters.overrides).containsExactly(override2.trackGroup, override2);
|
assertThat(trackSelectionParameters.overrides)
|
||||||
|
.containsExactly(override2.mediaTrackGroup, override2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -282,10 +288,11 @@ public final class TrackSelectionParametersTest {
|
|||||||
new TrackSelectionParameters.Builder(getApplicationContext())
|
new TrackSelectionParameters.Builder(getApplicationContext())
|
||||||
.addOverride(override1)
|
.addOverride(override1)
|
||||||
.addOverride(override2)
|
.addOverride(override2)
|
||||||
.clearOverride(override2.trackGroup)
|
.clearOverride(override2.mediaTrackGroup)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
assertThat(trackSelectionParameters.overrides).containsExactly(override1.trackGroup, override1);
|
assertThat(trackSelectionParameters.overrides)
|
||||||
|
.containsExactly(override1.mediaTrackGroup, override1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TrackGroup newTrackGroupWithIds(int... ids) {
|
private static TrackGroup newTrackGroupWithIds(int... ids) {
|
||||||
|
@ -1934,11 +1934,11 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
|||||||
// want the renderer to be enabled at all, so clear any existing selection.
|
// want the renderer to be enabled at all, so clear any existing selection.
|
||||||
@Nullable ExoTrackSelection.Definition selection;
|
@Nullable ExoTrackSelection.Definition selection;
|
||||||
if (!overrideForType.trackIndices.isEmpty()
|
if (!overrideForType.trackIndices.isEmpty()
|
||||||
&& mappedTrackInfo.getTrackGroups(rendererIndex).indexOf(overrideForType.trackGroup)
|
&& mappedTrackInfo.getTrackGroups(rendererIndex).indexOf(overrideForType.mediaTrackGroup)
|
||||||
!= -1) {
|
!= -1) {
|
||||||
selection =
|
selection =
|
||||||
new ExoTrackSelection.Definition(
|
new ExoTrackSelection.Definition(
|
||||||
overrideForType.trackGroup, Ints.toArray(overrideForType.trackIndices));
|
overrideForType.mediaTrackGroup, Ints.toArray(overrideForType.trackIndices));
|
||||||
} else {
|
} else {
|
||||||
selection = null;
|
selection = null;
|
||||||
}
|
}
|
||||||
|
@ -2240,7 +2240,7 @@ public final class DefaultTrackSelectorTest {
|
|||||||
assertThat(result.selections[2]).isNull();
|
assertThat(result.selections[2]).isNull();
|
||||||
ImmutableList<Tracks.Group> trackGroups = result.tracks.getGroups();
|
ImmutableList<Tracks.Group> trackGroups = result.tracks.getGroups();
|
||||||
assertThat(trackGroups).hasSize(1);
|
assertThat(trackGroups).hasSize(1);
|
||||||
assertThat(trackGroups.get(0).getTrackGroup()).isEqualTo(AUDIO_TRACK_GROUP);
|
assertThat(trackGroups.get(0).getMediaTrackGroup()).isEqualTo(AUDIO_TRACK_GROUP);
|
||||||
assertThat(trackGroups.get(0).isTrackSelected(0)).isTrue();
|
assertThat(trackGroups.get(0).isTrackSelected(0)).isTrue();
|
||||||
assertThat(trackGroups.get(0).getTrackSupport(0)).isEqualTo(FORMAT_HANDLED);
|
assertThat(trackGroups.get(0).getTrackSupport(0)).isEqualTo(FORMAT_HANDLED);
|
||||||
}
|
}
|
||||||
|
@ -76,13 +76,13 @@ public class TrackSelectionUtilTest {
|
|||||||
|
|
||||||
ImmutableList<Tracks.Group> trackGroups = tracks.getGroups();
|
ImmutableList<Tracks.Group> trackGroups = tracks.getGroups();
|
||||||
assertThat(trackGroups).hasSize(4);
|
assertThat(trackGroups).hasSize(4);
|
||||||
assertThat(trackGroups.get(0).getTrackGroup())
|
assertThat(trackGroups.get(0).getMediaTrackGroup())
|
||||||
.isEqualTo(mappedTrackInfo.getTrackGroups(0).get(0));
|
.isEqualTo(mappedTrackInfo.getTrackGroups(0).get(0));
|
||||||
assertThat(trackGroups.get(1).getTrackGroup())
|
assertThat(trackGroups.get(1).getMediaTrackGroup())
|
||||||
.isEqualTo(mappedTrackInfo.getTrackGroups(0).get(1));
|
.isEqualTo(mappedTrackInfo.getTrackGroups(0).get(1));
|
||||||
assertThat(trackGroups.get(2).getTrackGroup())
|
assertThat(trackGroups.get(2).getMediaTrackGroup())
|
||||||
.isEqualTo(mappedTrackInfo.getTrackGroups(1).get(0));
|
.isEqualTo(mappedTrackInfo.getTrackGroups(1).get(0));
|
||||||
assertThat(trackGroups.get(3).getTrackGroup())
|
assertThat(trackGroups.get(3).getMediaTrackGroup())
|
||||||
.isEqualTo(mappedTrackInfo.getUnmappedTrackGroups().get(0));
|
.isEqualTo(mappedTrackInfo.getUnmappedTrackGroups().get(0));
|
||||||
assertThat(trackGroups.get(0).getTrackSupport(0)).isEqualTo(FORMAT_HANDLED);
|
assertThat(trackGroups.get(0).getTrackSupport(0)).isEqualTo(FORMAT_HANDLED);
|
||||||
assertThat(trackGroups.get(1).getTrackSupport(0)).isEqualTo(FORMAT_UNSUPPORTED_SUBTYPE);
|
assertThat(trackGroups.get(1).getTrackSupport(0)).isEqualTo(FORMAT_UNSUPPORTED_SUBTYPE);
|
||||||
@ -135,9 +135,9 @@ public class TrackSelectionUtilTest {
|
|||||||
|
|
||||||
ImmutableList<Tracks.Group> trackGroups = tracks.getGroups();
|
ImmutableList<Tracks.Group> trackGroups = tracks.getGroups();
|
||||||
assertThat(trackGroups).hasSize(2);
|
assertThat(trackGroups).hasSize(2);
|
||||||
assertThat(trackGroups.get(0).getTrackGroup())
|
assertThat(trackGroups.get(0).getMediaTrackGroup())
|
||||||
.isEqualTo(mappedTrackInfo.getTrackGroups(0).get(0));
|
.isEqualTo(mappedTrackInfo.getTrackGroups(0).get(0));
|
||||||
assertThat(trackGroups.get(1).getTrackGroup())
|
assertThat(trackGroups.get(1).getMediaTrackGroup())
|
||||||
.isEqualTo(mappedTrackInfo.getTrackGroups(0).get(1));
|
.isEqualTo(mappedTrackInfo.getTrackGroups(0).get(1));
|
||||||
assertThat(trackGroups.get(0).getTrackSupport(0)).isEqualTo(FORMAT_HANDLED);
|
assertThat(trackGroups.get(0).getTrackSupport(0)).isEqualTo(FORMAT_HANDLED);
|
||||||
assertThat(trackGroups.get(1).getTrackSupport(0)).isEqualTo(FORMAT_HANDLED);
|
assertThat(trackGroups.get(1).getTrackSupport(0)).isEqualTo(FORMAT_HANDLED);
|
||||||
|
@ -1920,7 +1920,7 @@ public class PlayerControlView extends FrameLayout {
|
|||||||
|
|
||||||
private boolean hasSelectionOverride(TrackSelectionParameters trackSelectionParameters) {
|
private boolean hasSelectionOverride(TrackSelectionParameters trackSelectionParameters) {
|
||||||
for (int i = 0; i < tracks.size(); i++) {
|
for (int i = 0; i < tracks.size(); i++) {
|
||||||
TrackGroup trackGroup = tracks.get(i).trackGroup.getTrackGroup();
|
TrackGroup trackGroup = tracks.get(i).trackGroup.getMediaTrackGroup();
|
||||||
if (trackSelectionParameters.overrides.containsKey(trackGroup)) {
|
if (trackSelectionParameters.overrides.containsKey(trackGroup)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1994,9 +1994,10 @@ public class PlayerControlView extends FrameLayout {
|
|||||||
onBindViewHolderAtZeroPosition(holder);
|
onBindViewHolderAtZeroPosition(holder);
|
||||||
} else {
|
} else {
|
||||||
TrackInformation track = tracks.get(position - 1);
|
TrackInformation track = tracks.get(position - 1);
|
||||||
TrackGroup trackGroup = track.trackGroup.getTrackGroup();
|
TrackGroup mediaTrackGroup = track.trackGroup.getMediaTrackGroup();
|
||||||
TrackSelectionParameters params = player.getTrackSelectionParameters();
|
TrackSelectionParameters params = player.getTrackSelectionParameters();
|
||||||
boolean explicitlySelected = params.overrides.get(trackGroup) != null && track.isSelected();
|
boolean explicitlySelected =
|
||||||
|
params.overrides.get(mediaTrackGroup) != null && track.isSelected();
|
||||||
holder.textView.setText(track.trackName);
|
holder.textView.setText(track.trackName);
|
||||||
holder.checkView.setVisibility(explicitlySelected ? VISIBLE : INVISIBLE);
|
holder.checkView.setVisibility(explicitlySelected ? VISIBLE : INVISIBLE);
|
||||||
holder.itemView.setOnClickListener(
|
holder.itemView.setOnClickListener(
|
||||||
@ -2008,7 +2009,7 @@ public class PlayerControlView extends FrameLayout {
|
|||||||
.buildUpon()
|
.buildUpon()
|
||||||
.setOverrideForType(
|
.setOverrideForType(
|
||||||
new TrackSelectionOverride(
|
new TrackSelectionOverride(
|
||||||
trackGroup, ImmutableList.of(track.trackIndex)))
|
mediaTrackGroup, ImmutableList.of(track.trackIndex)))
|
||||||
.setTrackTypeDisabled(track.trackGroup.getType(), /* disabled= */ false)
|
.setTrackTypeDisabled(track.trackGroup.getType(), /* disabled= */ false)
|
||||||
.build());
|
.build());
|
||||||
onTrackSelection(track.trackName);
|
onTrackSelection(track.trackName);
|
||||||
|
@ -154,7 +154,9 @@ public final class TrackSelectionDialogBuilder {
|
|||||||
*/
|
*/
|
||||||
public TrackSelectionDialogBuilder setOverride(@Nullable TrackSelectionOverride override) {
|
public TrackSelectionDialogBuilder setOverride(@Nullable TrackSelectionOverride override) {
|
||||||
return setOverrides(
|
return setOverrides(
|
||||||
override == null ? Collections.emptyMap() : ImmutableMap.of(override.trackGroup, override));
|
override == null
|
||||||
|
? Collections.emptyMap()
|
||||||
|
: ImmutableMap.of(override.mediaTrackGroup, override));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,9 +72,9 @@ public class TrackSelectionView extends LinearLayout {
|
|||||||
HashMap<TrackGroup, TrackSelectionOverride> filteredOverrides = new HashMap<>();
|
HashMap<TrackGroup, TrackSelectionOverride> filteredOverrides = new HashMap<>();
|
||||||
for (int i = 0; i < trackGroups.size(); i++) {
|
for (int i = 0; i < trackGroups.size(); i++) {
|
||||||
Tracks.Group trackGroup = trackGroups.get(i);
|
Tracks.Group trackGroup = trackGroups.get(i);
|
||||||
@Nullable TrackSelectionOverride override = overrides.get(trackGroup.getTrackGroup());
|
@Nullable TrackSelectionOverride override = overrides.get(trackGroup.getMediaTrackGroup());
|
||||||
if (override != null && (allowMultipleOverrides || filteredOverrides.isEmpty())) {
|
if (override != null && (allowMultipleOverrides || filteredOverrides.isEmpty())) {
|
||||||
filteredOverrides.put(override.trackGroup, override);
|
filteredOverrides.put(override.mediaTrackGroup, override);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filteredOverrides;
|
return filteredOverrides;
|
||||||
@ -320,7 +320,8 @@ public class TrackSelectionView extends LinearLayout {
|
|||||||
disableView.setChecked(isDisabled);
|
disableView.setChecked(isDisabled);
|
||||||
defaultView.setChecked(!isDisabled && overrides.size() == 0);
|
defaultView.setChecked(!isDisabled && overrides.size() == 0);
|
||||||
for (int i = 0; i < trackViews.length; i++) {
|
for (int i = 0; i < trackViews.length; i++) {
|
||||||
@Nullable TrackSelectionOverride override = overrides.get(trackGroups.get(i).getTrackGroup());
|
@Nullable
|
||||||
|
TrackSelectionOverride override = overrides.get(trackGroups.get(i).getMediaTrackGroup());
|
||||||
for (int j = 0; j < trackViews[i].length; j++) {
|
for (int j = 0; j < trackViews[i].length; j++) {
|
||||||
if (override != null) {
|
if (override != null) {
|
||||||
TrackInfo trackInfo = (TrackInfo) Assertions.checkNotNull(trackViews[i][j].getTag());
|
TrackInfo trackInfo = (TrackInfo) Assertions.checkNotNull(trackViews[i][j].getTag());
|
||||||
@ -359,9 +360,9 @@ public class TrackSelectionView extends LinearLayout {
|
|||||||
private void onTrackViewClicked(View view) {
|
private void onTrackViewClicked(View view) {
|
||||||
isDisabled = false;
|
isDisabled = false;
|
||||||
TrackInfo trackInfo = (TrackInfo) Assertions.checkNotNull(view.getTag());
|
TrackInfo trackInfo = (TrackInfo) Assertions.checkNotNull(view.getTag());
|
||||||
TrackGroup trackGroup = trackInfo.trackGroup.getTrackGroup();
|
TrackGroup mediaTrackGroup = trackInfo.trackGroup.getMediaTrackGroup();
|
||||||
int trackIndex = trackInfo.trackIndex;
|
int trackIndex = trackInfo.trackIndex;
|
||||||
@Nullable TrackSelectionOverride override = overrides.get(trackGroup);
|
@Nullable TrackSelectionOverride override = overrides.get(mediaTrackGroup);
|
||||||
if (override == null) {
|
if (override == null) {
|
||||||
// Start new override.
|
// Start new override.
|
||||||
if (!allowMultipleOverrides && overrides.size() > 0) {
|
if (!allowMultipleOverrides && overrides.size() > 0) {
|
||||||
@ -369,7 +370,8 @@ public class TrackSelectionView extends LinearLayout {
|
|||||||
overrides.clear();
|
overrides.clear();
|
||||||
}
|
}
|
||||||
overrides.put(
|
overrides.put(
|
||||||
trackGroup, new TrackSelectionOverride(trackGroup, ImmutableList.of(trackIndex)));
|
mediaTrackGroup,
|
||||||
|
new TrackSelectionOverride(mediaTrackGroup, ImmutableList.of(trackIndex)));
|
||||||
} else {
|
} else {
|
||||||
// An existing override is being modified.
|
// An existing override is being modified.
|
||||||
ArrayList<Integer> trackIndices = new ArrayList<>(override.trackIndices);
|
ArrayList<Integer> trackIndices = new ArrayList<>(override.trackIndices);
|
||||||
@ -381,19 +383,20 @@ public class TrackSelectionView extends LinearLayout {
|
|||||||
trackIndices.remove((Integer) trackIndex);
|
trackIndices.remove((Integer) trackIndex);
|
||||||
if (trackIndices.isEmpty()) {
|
if (trackIndices.isEmpty()) {
|
||||||
// The last track has been removed, so remove the whole override.
|
// The last track has been removed, so remove the whole override.
|
||||||
overrides.remove(trackGroup);
|
overrides.remove(mediaTrackGroup);
|
||||||
} else {
|
} else {
|
||||||
overrides.put(trackGroup, new TrackSelectionOverride(trackGroup, trackIndices));
|
overrides.put(mediaTrackGroup, new TrackSelectionOverride(mediaTrackGroup, trackIndices));
|
||||||
}
|
}
|
||||||
} else if (!isCurrentlySelected) {
|
} else if (!isCurrentlySelected) {
|
||||||
if (isAdaptiveAllowed) {
|
if (isAdaptiveAllowed) {
|
||||||
// Add new track to adaptive override.
|
// Add new track to adaptive override.
|
||||||
trackIndices.add(trackIndex);
|
trackIndices.add(trackIndex);
|
||||||
overrides.put(trackGroup, new TrackSelectionOverride(trackGroup, trackIndices));
|
overrides.put(mediaTrackGroup, new TrackSelectionOverride(mediaTrackGroup, trackIndices));
|
||||||
} else {
|
} else {
|
||||||
// Replace existing track in override.
|
// Replace existing track in override.
|
||||||
overrides.put(
|
overrides.put(
|
||||||
trackGroup, new TrackSelectionOverride(trackGroup, ImmutableList.of(trackIndex)));
|
mediaTrackGroup,
|
||||||
|
new TrackSelectionOverride(mediaTrackGroup, ImmutableList.of(trackIndex)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user