Add IntRange annotation to onTrackCount

PiperOrigin-RevId: 496942702
This commit is contained in:
kimvde 2022-12-21 17:41:52 +00:00 committed by Marc Baechinger
parent 5c4d85c2ed
commit f67849afa1
3 changed files with 15 additions and 4 deletions

View file

@ -18,6 +18,7 @@ package androidx.media3.transformer;
import android.content.Context;
import android.os.Looper;
import androidx.annotation.IntRange;
import androidx.media3.common.Format;
import androidx.media3.common.MediaItem;
import androidx.media3.common.util.Clock;
@ -131,7 +132,7 @@ public interface AssetLoader {
void onDurationUs(long durationUs);
/** Called when the number of tracks output by the asset loader is known. */
void onTrackCount(int trackCount);
void onTrackCount(@IntRange(from = 1) int trackCount);
/**
* Called when the information on a track is known.

View file

@ -16,6 +16,7 @@
package androidx.media3.transformer;
import static androidx.media3.common.PlaybackException.ERROR_CODE_FAILED_RUNTIME_CHECK;
import static androidx.media3.common.util.Assertions.checkStateNotNull;
import static androidx.media3.exoplayer.DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS;
import static androidx.media3.exoplayer.DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS;
@ -350,7 +351,15 @@ public final class ExoPlayerAssetLoader implements AssetLoader {
if (tracks.isTypeSelected(C.TRACK_TYPE_VIDEO)) {
trackCount++;
}
assetLoaderListener.onTrackCount(trackCount);
if (trackCount == 0) {
assetLoaderListener.onError(
new PlaybackException(
"The asset loader has no track to output.",
/* cause= */ null,
ERROR_CODE_FAILED_RUNTIME_CHECK));
} else {
assetLoaderListener.onTrackCount(trackCount);
}
}
@Override

View file

@ -401,8 +401,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Override
public void onTrackCount(int trackCount) {
if (trackCount == 0) {
onError(new IllegalStateException("The output does not contain any tracks."));
if (trackCount <= 0) {
onError(new IllegalStateException("AssetLoader instances must provide at least 1 track."));
return;
}
this.trackCount.set(trackCount);
if (forceSilentAudio) {