Update ClippedPlaybackTest to fail on a player error (vs timing out)

Also explicitly use a synchronized list to collect cues. The previous
bare `ArrayList` was probably fine, because the `ConditionVariable`
creates a memory barrier between the main thread and the test thread,
but this seems more explicit (and any performance implications of the
synchronization don't matter for this test).

PiperOrigin-RevId: 621523824
This commit is contained in:
ibaker 2024-04-03 08:01:50 -07:00 committed by Copybara-Service
parent bf21f1edd5
commit 85793ea2ca

View File

@ -24,6 +24,7 @@ import androidx.media3.common.C;
import androidx.media3.common.MediaItem;
import androidx.media3.common.MediaItem.SubtitleConfiguration;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.Player;
import androidx.media3.common.text.Cue;
import androidx.media3.common.text.CueGroup;
@ -33,6 +34,7 @@ import androidx.media3.exoplayer.source.DefaultMediaSourceFactory;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
@ -180,10 +182,12 @@ public final class ClippedPlaybackTest {
private final ConditionVariable playbackEnded;
private final List<List<Cue>> cues;
private final AtomicReference<PlaybackException> playerError;
private TextCapturingPlaybackListener() {
playbackEnded = new ConditionVariable();
cues = new ArrayList<>();
cues = Collections.synchronizedList(new ArrayList<>());
playerError = new AtomicReference<>();
}
@Override
@ -198,8 +202,18 @@ public final class ClippedPlaybackTest {
}
}
public void block() throws InterruptedException {
@Override
public void onPlayerError(PlaybackException error) {
playerError.set(error);
playbackEnded.open();
}
public void block() throws InterruptedException, PlaybackException {
playbackEnded.block();
PlaybackException playerError = this.playerError.get();
if (playerError != null) {
throw playerError;
}
}
}
}