mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Add getFormat and length to TrackGroupInfo
PiperOrigin-RevId: 428520090
This commit is contained in:
parent
015592f534
commit
76839a02d6
@ -38,12 +38,17 @@ import java.util.List;
|
||||
|
||||
/** Information about groups of tracks. */
|
||||
public final class TracksInfo implements Bundleable {
|
||||
|
||||
/**
|
||||
* Information about a single group of tracks, including the underlying {@link TrackGroup}, the
|
||||
* {@link C.TrackType type} of tracks it contains, and the level to which each track is supported
|
||||
* by the player.
|
||||
*/
|
||||
public static final class TrackGroupInfo implements Bundleable {
|
||||
|
||||
/** The number of tracks in the group. */
|
||||
public final int length;
|
||||
|
||||
private final TrackGroup trackGroup;
|
||||
private final @C.FormatSupport int[] trackSupport;
|
||||
private final @C.TrackType int trackType;
|
||||
@ -63,7 +68,7 @@ public final class TracksInfo implements Bundleable {
|
||||
@C.FormatSupport int[] trackSupport,
|
||||
@C.TrackType int trackType,
|
||||
boolean[] tracksSelected) {
|
||||
int length = trackGroup.length;
|
||||
length = trackGroup.length;
|
||||
checkArgument(length == trackSupport.length && length == tracksSelected.length);
|
||||
this.trackGroup = trackGroup;
|
||||
this.trackSupport = trackSupport.clone();
|
||||
@ -71,11 +76,21 @@ public final class TracksInfo implements Bundleable {
|
||||
this.trackSelected = tracksSelected.clone();
|
||||
}
|
||||
|
||||
/** Returns the {@link TrackGroup} described by this {@code TrackGroupInfo}. */
|
||||
/** Returns the underlying {@link TrackGroup}. */
|
||||
public TrackGroup getTrackGroup() {
|
||||
return trackGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Format} for a specified track.
|
||||
*
|
||||
* @param trackIndex The index of the track in the {@link TrackGroup}.
|
||||
* @return The {@link Format} of the track.
|
||||
*/
|
||||
public Format getTrackFormat(int trackIndex) {
|
||||
return trackGroup.getFormat(trackIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the level of support for a specified track.
|
||||
*
|
||||
|
@ -49,7 +49,6 @@ import androidx.media3.common.ParserException;
|
||||
import androidx.media3.common.PlaybackException;
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.media3.common.Timeline;
|
||||
import androidx.media3.common.TrackGroup;
|
||||
import androidx.media3.common.TracksInfo;
|
||||
import androidx.media3.common.TracksInfo.TrackGroupInfo;
|
||||
import androidx.media3.common.VideoSize;
|
||||
@ -825,10 +824,9 @@ public final class MediaMetricsListener
|
||||
@Nullable
|
||||
private static DrmInitData getDrmInitData(ImmutableList<TrackGroupInfo> trackGroupInfos) {
|
||||
for (TrackGroupInfo trackGroupInfo : trackGroupInfos) {
|
||||
TrackGroup trackGroup = trackGroupInfo.getTrackGroup();
|
||||
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
|
||||
for (int trackIndex = 0; trackIndex < trackGroupInfo.length; trackIndex++) {
|
||||
if (trackGroupInfo.isTrackSelected(trackIndex)) {
|
||||
@Nullable DrmInitData drmInitData = trackGroup.getFormat(trackIndex).drmInitData;
|
||||
@Nullable DrmInitData drmInitData = trackGroupInfo.getTrackFormat(trackIndex).drmInitData;
|
||||
if (drmInitData != null) {
|
||||
return drmInitData;
|
||||
}
|
||||
|
@ -268,9 +268,8 @@ public class EventLogger implements AnalyticsListener {
|
||||
ImmutableList<TracksInfo.TrackGroupInfo> trackGroupInfos = tracksInfo.getTrackGroupInfos();
|
||||
for (int groupIndex = 0; groupIndex < trackGroupInfos.size(); groupIndex++) {
|
||||
TracksInfo.TrackGroupInfo trackGroupInfo = trackGroupInfos.get(groupIndex);
|
||||
TrackGroup trackGroup = trackGroupInfo.getTrackGroup();
|
||||
logd(" group [");
|
||||
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
|
||||
for (int trackIndex = 0; trackIndex < trackGroupInfo.length; trackIndex++) {
|
||||
String status = getTrackStatusString(trackGroupInfo.isTrackSelected(trackIndex));
|
||||
String formatSupport = getFormatSupportString(trackGroupInfo.getTrackSupport(trackIndex));
|
||||
logd(
|
||||
@ -279,7 +278,7 @@ public class EventLogger implements AnalyticsListener {
|
||||
+ " Track:"
|
||||
+ trackIndex
|
||||
+ ", "
|
||||
+ Format.toLogString(trackGroup.getFormat(trackIndex))
|
||||
+ Format.toLogString(trackGroupInfo.getTrackFormat(trackIndex))
|
||||
+ ", supported="
|
||||
+ formatSupport);
|
||||
}
|
||||
|
@ -7984,7 +7984,7 @@ public final class ExoPlayerTest {
|
||||
assertThat(timelineAfterError.get().getWindowCount()).isEqualTo(1);
|
||||
assertThat(mediaItemIndexAfterError.get()).isEqualTo(0);
|
||||
assertThat(trackInfosAfterError.get().getTrackGroupInfos()).hasSize(1);
|
||||
assertThat(trackInfosAfterError.get().getTrackGroupInfos().get(0).getTrackGroup().getFormat(0))
|
||||
assertThat(trackInfosAfterError.get().getTrackGroupInfos().get(0).getTrackFormat(0))
|
||||
.isEqualTo(ExoPlayerTestRunner.AUDIO_FORMAT);
|
||||
assertThat(trackSelectionsAfterError.get().get(0)).isNull(); // Video renderer.
|
||||
assertThat(trackSelectionsAfterError.get().get(1)).isNotNull(); // Audio renderer.
|
||||
|
@ -1124,12 +1124,12 @@ public class PlayerControlView extends FrameLayout {
|
||||
if (trackGroupInfo.getTrackType() != trackType) {
|
||||
continue;
|
||||
}
|
||||
TrackGroup trackGroup = trackGroupInfo.getTrackGroup();
|
||||
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
|
||||
for (int trackIndex = 0; trackIndex < trackGroupInfo.length; trackIndex++) {
|
||||
if (!trackGroupInfo.isTrackSupported(trackIndex)) {
|
||||
continue;
|
||||
}
|
||||
String trackName = trackNameProvider.getTrackName(trackGroup.getFormat(trackIndex));
|
||||
String trackName =
|
||||
trackNameProvider.getTrackName(trackGroupInfo.getTrackFormat(trackIndex));
|
||||
tracks.add(new TrackInformation(tracksInfo, trackGroupIndex, trackIndex, trackName));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user