mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Let FakeTrackSelection extend BaseTrackSelection
This fixes a bug in getIndexInTrackGroup PiperOrigin-RevId: 687336621
This commit is contained in:
parent
0108fb938e
commit
ceac959c29
@ -19,11 +19,11 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.Format;
|
|
||||||
import androidx.media3.common.TrackGroup;
|
import androidx.media3.common.TrackGroup;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import androidx.media3.exoplayer.source.chunk.MediaChunk;
|
import androidx.media3.exoplayer.source.chunk.MediaChunk;
|
||||||
import androidx.media3.exoplayer.source.chunk.MediaChunkIterator;
|
import androidx.media3.exoplayer.source.chunk.MediaChunkIterator;
|
||||||
|
import androidx.media3.exoplayer.trackselection.BaseTrackSelection;
|
||||||
import androidx.media3.exoplayer.trackselection.ExoTrackSelection;
|
import androidx.media3.exoplayer.trackselection.ExoTrackSelection;
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -33,7 +33,7 @@ import java.util.List;
|
|||||||
* of calls to its methods.
|
* of calls to its methods.
|
||||||
*/
|
*/
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public final class FakeTrackSelection implements ExoTrackSelection {
|
public final class FakeTrackSelection extends BaseTrackSelection {
|
||||||
|
|
||||||
private final TrackGroup rendererTrackGroup;
|
private final TrackGroup rendererTrackGroup;
|
||||||
private final int selectedIndex;
|
private final int selectedIndex;
|
||||||
@ -47,53 +47,11 @@ public final class FakeTrackSelection implements ExoTrackSelection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FakeTrackSelection(TrackGroup rendererTrackGroup, int selectedIndex) {
|
public FakeTrackSelection(TrackGroup rendererTrackGroup, int selectedIndex) {
|
||||||
|
super(rendererTrackGroup, getAllTrackIndices(rendererTrackGroup));
|
||||||
this.rendererTrackGroup = rendererTrackGroup;
|
this.rendererTrackGroup = rendererTrackGroup;
|
||||||
this.selectedIndex = selectedIndex;
|
this.selectedIndex = selectedIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TrackSelection implementation.
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getType() {
|
|
||||||
return TYPE_UNSET;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TrackGroup getTrackGroup() {
|
|
||||||
return rendererTrackGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int length() {
|
|
||||||
return rendererTrackGroup.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Format getFormat(int index) {
|
|
||||||
return rendererTrackGroup.getFormat(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getIndexInTrackGroup(int index) {
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int indexOf(Format format) {
|
|
||||||
assertThat(isEnabled).isTrue();
|
|
||||||
for (int i = 0; i < rendererTrackGroup.length; i++) {
|
|
||||||
if (rendererTrackGroup.getFormat(i).equals(format)) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int indexOf(int indexInTrackGroup) {
|
|
||||||
return indexInTrackGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExoTrackSelection specific methods.
|
// ExoTrackSelection specific methods.
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -112,16 +70,6 @@ public final class FakeTrackSelection implements ExoTrackSelection {
|
|||||||
isEnabled = false;
|
isEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Format getSelectedFormat() {
|
|
||||||
return rendererTrackGroup.getFormat(selectedIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSelectedIndexInTrackGroup() {
|
|
||||||
return selectedIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSelectedIndex() {
|
public int getSelectedIndex() {
|
||||||
return selectedIndex;
|
return selectedIndex;
|
||||||
@ -138,11 +86,6 @@ public final class FakeTrackSelection implements ExoTrackSelection {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlaybackSpeed(float playbackSpeed) {
|
|
||||||
// Do nothing.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateSelectedTrack(
|
public void updateSelectedTrack(
|
||||||
long playbackPositionUs,
|
long playbackPositionUs,
|
||||||
@ -192,4 +135,12 @@ public final class FakeTrackSelection implements ExoTrackSelection {
|
|||||||
return Objects.hashCode(
|
return Objects.hashCode(
|
||||||
rendererTrackGroup, enableCount, releaseCount, isEnabled, selectedIndex);
|
rendererTrackGroup, enableCount, releaseCount, isEnabled, selectedIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int[] getAllTrackIndices(TrackGroup trackGroup) {
|
||||||
|
int[] indices = new int[trackGroup.length];
|
||||||
|
for (int i = 0; i < indices.length; i++) {
|
||||||
|
indices[i] = i;
|
||||||
|
}
|
||||||
|
return indices;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user