Search in sources :

Example 41 with Callback

use of com.google.android.exoplayer2.offline.DownloadHelper.Callback in project ExoPlayer by google.

the class FakeClockTest method createHandler_sendMessageAtFrontOfQueue_sendsMessageFirst.

@Test
public void createHandler_sendMessageAtFrontOfQueue_sendsMessageFirst() {
    HandlerThread handlerThread = new HandlerThread("FakeClockTest");
    handlerThread.start();
    FakeClock fakeClock = new FakeClock(/* initialTimeMs= */
    0);
    TestCallback callback = new TestCallback();
    HandlerWrapper handler = fakeClock.createHandler(handlerThread.getLooper(), callback);
    handler.obtainMessage(/* what= */
    1).sendToTarget();
    handler.sendMessageAtFrontOfQueue(handler.obtainMessage(/* what= */
    2));
    handler.sendMessageAtFrontOfQueue(handler.obtainMessage(/* what= */
    3));
    handler.obtainMessage(/* what= */
    4).sendToTarget();
    ShadowLooper.idleMainLooper();
    shadowOf(handler.getLooper()).idle();
    assertThat(callback.messages).containsExactly(new MessageData(/* what= */
    3, /* arg1= */
    0, /* arg2= */
    0, /* obj=*/
    null), new MessageData(/* what= */
    2, /* arg1= */
    0, /* arg2= */
    0, /* obj=*/
    null), new MessageData(/* what= */
    1, /* arg1= */
    0, /* arg2= */
    0, /* obj=*/
    null), new MessageData(/* what= */
    4, /* arg1= */
    0, /* arg2= */
    0, /* obj=*/
    null)).inOrder();
}
Also used : HandlerThread(android.os.HandlerThread) HandlerWrapper(com.google.android.exoplayer2.util.HandlerWrapper) Test(org.junit.Test)

Example 42 with Callback

use of com.google.android.exoplayer2.offline.DownloadHelper.Callback in project ExoPlayer by google.

the class SingleSampleMediaPeriod method continueLoading.

@Override
public boolean continueLoading(long positionUs) {
    if (loadingFinished || loader.isLoading() || loader.hasFatalError()) {
        return false;
    }
    DataSource dataSource = dataSourceFactory.createDataSource();
    if (transferListener != null) {
        dataSource.addTransferListener(transferListener);
    }
    SourceLoadable loadable = new SourceLoadable(dataSpec, dataSource);
    long elapsedRealtimeMs = loader.startLoading(loadable, /* callback= */
    this, loadErrorHandlingPolicy.getMinimumLoadableRetryCount(C.DATA_TYPE_MEDIA));
    eventDispatcher.loadStarted(new LoadEventInfo(loadable.loadTaskId, dataSpec, elapsedRealtimeMs), C.DATA_TYPE_MEDIA, C.TRACK_TYPE_UNKNOWN, format, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
    null, /* mediaStartTimeUs= */
    0, durationUs);
    return true;
}
Also used : StatsDataSource(com.google.android.exoplayer2.upstream.StatsDataSource) DataSource(com.google.android.exoplayer2.upstream.DataSource)

Aggregations

Test (org.junit.Test)23 ArrayList (java.util.ArrayList)10 HandlerThread (android.os.HandlerThread)9 Nullable (androidx.annotation.Nullable)9 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)9 HandlerWrapper (com.google.android.exoplayer2.util.HandlerWrapper)9 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)8 PlaybackParameters (com.google.android.exoplayer2.PlaybackParameters)7 Player (com.google.android.exoplayer2.Player)6 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)6 ApplicationProvider (androidx.test.core.app.ApplicationProvider)5 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)5 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)5 MediaSource (com.google.android.exoplayer2.source.MediaSource)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 RunWith (org.junit.runner.RunWith)5 LoadEventInfo (com.google.android.exoplayer2.source.LoadEventInfo)4 ImmutableList (com.google.common.collect.ImmutableList)4 SurfaceTexture (android.graphics.SurfaceTexture)3