use of com.google.android.exoplayer2.util.ConditionVariable in project ExoPlayer by google.
the class DrmPlaybackTest method clearkeyPlayback.
@Test
public void clearkeyPlayback() throws Exception {
MockWebServer mockWebServer = new MockWebServer();
mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(CLEARKEY_RESPONSE));
mockWebServer.start();
MediaItem mediaItem = new MediaItem.Builder().setUri("asset:///media/drm/sample_fragmented_clearkey.mp4").setDrmConfiguration(new MediaItem.DrmConfiguration.Builder(C.CLEARKEY_UUID).setLicenseUri(mockWebServer.url("license").toString()).build()).build();
AtomicReference<ExoPlayer> player = new AtomicReference<>();
ConditionVariable playbackComplete = new ConditionVariable();
AtomicReference<PlaybackException> playbackException = new AtomicReference<>();
getInstrumentation().runOnMainSync(() -> {
player.set(new ExoPlayer.Builder(getInstrumentation().getContext()).build());
player.get().addListener(new Player.Listener() {
@Override
public void onPlaybackStateChanged(@Player.State int playbackState) {
if (playbackState == Player.STATE_ENDED) {
playbackComplete.open();
}
}
@Override
public void onPlayerError(PlaybackException error) {
playbackException.set(error);
playbackComplete.open();
}
});
player.get().setMediaItem(mediaItem);
player.get().prepare();
player.get().play();
});
playbackComplete.block();
getInstrumentation().runOnMainSync(() -> player.get().release());
getInstrumentation().waitForIdleSync();
assertThat(playbackException.get()).isNull();
}
use of com.google.android.exoplayer2.util.ConditionVariable in project ExoPlayer by google.
the class CronetDataSourceTest method connectTimeout.
@Test
public void connectTimeout() throws InterruptedException {
long startTimeMs = SystemClock.elapsedRealtime();
final ConditionVariable startCondition = buildUrlRequestStartedCondition();
final CountDownLatch timedOutLatch = new CountDownLatch(1);
new Thread() {
@Override
public void run() {
try {
dataSourceUnderTest.open(testDataSpec);
fail();
} catch (HttpDataSourceException e) {
// Expected.
assertThat(e).isInstanceOf(CronetDataSource.OpenException.class);
assertThat(e).hasCauseThat().isInstanceOf(SocketTimeoutException.class);
assertThat(((CronetDataSource.OpenException) e).cronetConnectionStatus).isEqualTo(TEST_CONNECTION_STATUS);
timedOutLatch.countDown();
}
}
}.start();
startCondition.block();
// We should still be trying to open.
assertNotCountedDown(timedOutLatch);
// We should still be trying to open as we approach the timeout.
setSystemClockInMsAndTriggerPendingMessages(/* nowMs= */
startTimeMs + TEST_CONNECT_TIMEOUT_MS - 1);
assertNotCountedDown(timedOutLatch);
// Now we timeout.
setSystemClockInMsAndTriggerPendingMessages(/* nowMs= */
startTimeMs + TEST_CONNECT_TIMEOUT_MS + 10);
timedOutLatch.await();
verify(mockTransferListener, never()).onTransferStart(dataSourceUnderTest, testDataSpec, /* isNetwork= */
true);
}
use of com.google.android.exoplayer2.util.ConditionVariable in project ExoPlayer by google.
the class CronetDataSourceTest method connectInterrupted.
@Test
public void connectInterrupted() throws InterruptedException {
long startTimeMs = SystemClock.elapsedRealtime();
final ConditionVariable startCondition = buildUrlRequestStartedCondition();
final CountDownLatch timedOutLatch = new CountDownLatch(1);
Thread thread = new Thread() {
@Override
public void run() {
try {
dataSourceUnderTest.open(testDataSpec);
fail();
} catch (HttpDataSourceException e) {
// Expected.
assertThat(e).isInstanceOf(CronetDataSource.OpenException.class);
assertThat(e).hasCauseThat().isInstanceOf(InterruptedIOException.class);
assertThat(((CronetDataSource.OpenException) e).cronetConnectionStatus).isEqualTo(TEST_INVALID_CONNECTION_STATUS);
timedOutLatch.countDown();
}
}
};
thread.start();
startCondition.block();
// We should still be trying to open.
assertNotCountedDown(timedOutLatch);
// We should still be trying to open as we approach the timeout.
setSystemClockInMsAndTriggerPendingMessages(/* nowMs= */
startTimeMs + TEST_CONNECT_TIMEOUT_MS - 1);
assertNotCountedDown(timedOutLatch);
// Now we interrupt.
thread.interrupt();
timedOutLatch.await();
verify(mockTransferListener, never()).onTransferStart(dataSourceUnderTest, testDataSpec, /* isNetwork= */
true);
}
use of com.google.android.exoplayer2.util.ConditionVariable in project ExoPlayer by google.
the class RobolectricUtilTest method createRobolectricConditionVariable_blockWithTimeout_blocksForAtLeastTimeout.
@Test
public void createRobolectricConditionVariable_blockWithTimeout_blocksForAtLeastTimeout() throws InterruptedException {
ConditionVariable conditionVariable = RobolectricUtil.createRobolectricConditionVariable();
long startTimeMs = System.currentTimeMillis();
assertThat(conditionVariable.block(/* timeoutMs= */
500)).isFalse();
long endTimeMs = System.currentTimeMillis();
assertThat(endTimeMs - startTimeMs).isAtLeast(500);
}
use of com.google.android.exoplayer2.util.ConditionVariable in project ExoPlayer by google.
the class RobolectricUtilTest method createRobolectricConditionVariable_blockWithTimeout_timesOut.
@Test
public void createRobolectricConditionVariable_blockWithTimeout_timesOut() throws InterruptedException {
ConditionVariable conditionVariable = RobolectricUtil.createRobolectricConditionVariable();
assertThat(conditionVariable.block(/* timeoutMs= */
1)).isFalse();
assertThat(conditionVariable.isOpen()).isFalse();
}
Aggregations