Search in sources :

Example 21 with FakeRenderer

use of com.google.android.exoplayer2.testutil.FakeRenderer in project ExoPlayer by google.

the class DefaultAnalyticsCollectorTest method onPlayerError_thrownDuringRendererReplaceStreamAtPeriodTransition_isReportedForNewPeriod.

@Test
public void onPlayerError_thrownDuringRendererReplaceStreamAtPeriodTransition_isReportedForNewPeriod() throws Exception {
    FakeMediaSource source = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.AUDIO_FORMAT);
    RenderersFactory renderersFactory = (eventHandler, videoListener, audioListener, textOutput, metadataOutput) -> new Renderer[] { new FakeRenderer(C.TRACK_TYPE_AUDIO) {

        private int streamChangeCount = 0;

        @Override
        protected void onStreamChanged(Format[] formats, long startPositionUs, long offsetUs) throws ExoPlaybackException {
            // period transition (as the first time is when enabling the stream initially).
            if (++streamChangeCount == 2) {
                throw createRendererException(new IllegalStateException(), ExoPlayerTestRunner.AUDIO_FORMAT, PlaybackException.ERROR_CODE_UNSPECIFIED);
            }
        }
    } };
    TestAnalyticsListener listener = runAnalyticsTest(new ConcatenatingMediaSource(source, source), /* actionSchedule= */
    null, renderersFactory);
    populateEventIds(listener.lastReportedTimeline);
    assertThat(listener.getEvents(EVENT_PLAYER_ERROR)).containsExactly(period1);
}
Also used : ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException) LoadEventInfo(com.google.android.exoplayer2.source.LoadEventInfo) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) EVENT_TIMELINE_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_TIMELINE_CHANGED) ExoMediaDrm(com.google.android.exoplayer2.drm.ExoMediaDrm) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) EVENT_RENDERED_FIRST_FRAME(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_RENDERED_FIRST_FRAME) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) MimeTypes(com.google.android.exoplayer2.util.MimeTypes) Looper(android.os.Looper) EVENT_AUDIO_DECODER_INITIALIZED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_AUDIO_DECODER_INITIALIZED) C(com.google.android.exoplayer2.C) EVENT_LOAD_STARTED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_LOAD_STARTED) DefaultDrmSessionManager(com.google.android.exoplayer2.drm.DefaultDrmSessionManager) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) Surface(android.view.Surface) EVENT_AUDIO_ENABLED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_AUDIO_ENABLED) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) FakeClock(com.google.android.exoplayer2.testutil.FakeClock) FakeAudioRenderer(com.google.android.exoplayer2.testutil.FakeAudioRenderer) Nullable(androidx.annotation.Nullable) Timeline(com.google.android.exoplayer2.Timeline) EVENT_PLAYER_ERROR(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_PLAYER_ERROR) RobolectricUtil(com.google.android.exoplayer2.robolectric.RobolectricUtil) ArgumentMatchers.anyFloat(org.mockito.ArgumentMatchers.anyFloat) EVENT_POSITION_DISCONTINUITY(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_POSITION_DISCONTINUITY) EVENT_VIDEO_INPUT_FORMAT_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_VIDEO_INPUT_FORMAT_CHANGED) EVENT_IS_PLAYING_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_IS_PLAYING_CHANGED) Mockito.mock(org.mockito.Mockito.mock) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) RunWith(org.junit.runner.RunWith) PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.spy(org.mockito.Mockito.spy) EVENT_PLAYBACK_PARAMETERS_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_PLAYBACK_PARAMETERS_CHANGED) TestUtil(com.google.android.exoplayer2.testutil.TestUtil) EVENT_VIDEO_SIZE_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_VIDEO_SIZE_CHANGED) ArrayList(java.util.ArrayList) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) EVENT_VIDEO_FRAME_PROCESSING_OFFSET(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_VIDEO_FRAME_PROCESSING_OFFSET) MediaDrmCallbackException(com.google.android.exoplayer2.drm.MediaDrmCallbackException) EVENT_DRM_SESSION_ACQUIRED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_DRM_SESSION_ACQUIRED) Clock(com.google.android.exoplayer2.util.Clock) ShadowLooper(org.robolectric.shadows.ShadowLooper) IOException(java.io.IOException) Test(org.junit.Test) EVENT_VIDEO_DISABLED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_VIDEO_DISABLED) TestPlayerRunHelper(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper) TracksInfo(com.google.android.exoplayer2.TracksInfo) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) DrmInitData(com.google.android.exoplayer2.drm.DrmInitData) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) Util(com.google.android.exoplayer2.util.Util) EVENT_VIDEO_ENABLED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_VIDEO_ENABLED) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) Player(com.google.android.exoplayer2.Player) EVENT_VIDEO_DECODER_INITIALIZED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_VIDEO_DECODER_INITIALIZED) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) ApplicationProvider(androidx.test.core.app.ApplicationProvider) Format(com.google.android.exoplayer2.Format) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EVENT_IS_LOADING_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_IS_LOADING_CHANGED) Method(java.lang.reflect.Method) MediaSource(com.google.android.exoplayer2.source.MediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) EVENT_PLAYER_RELEASED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_PLAYER_RELEASED) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) EVENT_PLAYBACK_STATE_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_PLAYBACK_STATE_CHANGED) MediaItem(com.google.android.exoplayer2.MediaItem) EVENT_DRM_KEYS_LOADED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_DRM_KEYS_LOADED) END_OF_STREAM_ITEM(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM) EVENT_TRACKS_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_TRACKS_CHANGED) UUID(java.util.UUID) EVENT_DRM_SESSION_MANAGER_ERROR(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_DRM_SESSION_MANAGER_ERROR) SparseArray(android.util.SparseArray) FakeSampleStreamItem.oneByteSample(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.oneByteSample) DrmSession(com.google.android.exoplayer2.drm.DrmSession) List(java.util.List) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Mockito.inOrder(org.mockito.Mockito.inOrder) EVENT_DRM_SESSION_RELEASED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_DRM_SESSION_RELEASED) PlaybackException(com.google.android.exoplayer2.PlaybackException) MediaLoadData(com.google.android.exoplayer2.source.MediaLoadData) FakeVideoRenderer(com.google.android.exoplayer2.testutil.FakeVideoRenderer) EVENT_AUDIO_POSITION_ADVANCING(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_AUDIO_POSITION_ADVANCING) Metadata(com.google.android.exoplayer2.metadata.Metadata) EVENT_LOAD_COMPLETED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_LOAD_COMPLETED) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DecoderCounters(com.google.android.exoplayer2.decoder.DecoderCounters) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) AtomicReference(java.util.concurrent.atomic.AtomicReference) EVENT_LOAD_ERROR(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_LOAD_ERROR) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) ConditionVariable(com.google.android.exoplayer2.util.ConditionVariable) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) VideoSize(com.google.android.exoplayer2.video.VideoSize) SurfaceTexture(android.graphics.SurfaceTexture) Window(com.google.android.exoplayer2.Timeline.Window) EVENT_MEDIA_ITEM_TRANSITION(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_MEDIA_ITEM_TRANSITION) MediaDrmCallback(com.google.android.exoplayer2.drm.MediaDrmCallback) InOrder(org.mockito.InOrder) Iterator(java.util.Iterator) EVENT_AUDIO_DISABLED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_AUDIO_DISABLED) EVENT_DOWNSTREAM_FORMAT_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_DOWNSTREAM_FORMAT_CHANGED) Truth.assertThat(com.google.common.truth.Truth.assertThat) EVENT_DROPPED_VIDEO_FRAMES(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_DROPPED_VIDEO_FRAMES) Mockito.verify(org.mockito.Mockito.verify) EVENT_PLAY_WHEN_READY_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_PLAY_WHEN_READY_CHANGED) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeExoMediaDrm(com.google.android.exoplayer2.testutil.FakeExoMediaDrm) EVENT_AUDIO_INPUT_FORMAT_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_AUDIO_INPUT_FORMAT_CHANGED) Renderer(com.google.android.exoplayer2.Renderer) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeAudioRenderer(com.google.android.exoplayer2.testutil.FakeAudioRenderer) FakeVideoRenderer(com.google.android.exoplayer2.testutil.FakeVideoRenderer) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) Renderer(com.google.android.exoplayer2.Renderer) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) Test(org.junit.Test)

Example 22 with FakeRenderer

use of com.google.android.exoplayer2.testutil.FakeRenderer in project ExoPlayer by google.

the class DefaultAnalyticsCollectorTest method onPlayerError_thrownDuringRendererEnableAtPeriodTransition_isReportedForNewPeriod.

@Test
public void onPlayerError_thrownDuringRendererEnableAtPeriodTransition_isReportedForNewPeriod() throws Exception {
    FakeMediaSource source0 = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT);
    FakeMediaSource source1 = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.AUDIO_FORMAT);
    RenderersFactory renderersFactory = (eventHandler, videoListener, audioListener, textOutput, metadataOutput) -> new Renderer[] { new FakeRenderer(C.TRACK_TYPE_VIDEO), new FakeRenderer(C.TRACK_TYPE_AUDIO) {

        @Override
        protected void onEnabled(boolean joining, boolean mayRenderStartOfStream) throws ExoPlaybackException {
            // Fail when enabling the renderer. This will happen during the period transition.
            throw createRendererException(new IllegalStateException(), ExoPlayerTestRunner.AUDIO_FORMAT, PlaybackException.ERROR_CODE_UNSPECIFIED);
        }
    } };
    TestAnalyticsListener listener = runAnalyticsTest(new ConcatenatingMediaSource(source0, source1), /* actionSchedule= */
    null, renderersFactory);
    populateEventIds(listener.lastReportedTimeline);
    assertThat(listener.getEvents(EVENT_PLAYER_ERROR)).containsExactly(period1);
}
Also used : ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException) LoadEventInfo(com.google.android.exoplayer2.source.LoadEventInfo) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) EVENT_TIMELINE_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_TIMELINE_CHANGED) ExoMediaDrm(com.google.android.exoplayer2.drm.ExoMediaDrm) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) EVENT_RENDERED_FIRST_FRAME(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_RENDERED_FIRST_FRAME) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) MimeTypes(com.google.android.exoplayer2.util.MimeTypes) Looper(android.os.Looper) EVENT_AUDIO_DECODER_INITIALIZED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_AUDIO_DECODER_INITIALIZED) C(com.google.android.exoplayer2.C) EVENT_LOAD_STARTED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_LOAD_STARTED) DefaultDrmSessionManager(com.google.android.exoplayer2.drm.DefaultDrmSessionManager) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) Surface(android.view.Surface) EVENT_AUDIO_ENABLED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_AUDIO_ENABLED) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) FakeClock(com.google.android.exoplayer2.testutil.FakeClock) FakeAudioRenderer(com.google.android.exoplayer2.testutil.FakeAudioRenderer) Nullable(androidx.annotation.Nullable) Timeline(com.google.android.exoplayer2.Timeline) EVENT_PLAYER_ERROR(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_PLAYER_ERROR) RobolectricUtil(com.google.android.exoplayer2.robolectric.RobolectricUtil) ArgumentMatchers.anyFloat(org.mockito.ArgumentMatchers.anyFloat) EVENT_POSITION_DISCONTINUITY(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_POSITION_DISCONTINUITY) EVENT_VIDEO_INPUT_FORMAT_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_VIDEO_INPUT_FORMAT_CHANGED) EVENT_IS_PLAYING_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_IS_PLAYING_CHANGED) Mockito.mock(org.mockito.Mockito.mock) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) RunWith(org.junit.runner.RunWith) PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.spy(org.mockito.Mockito.spy) EVENT_PLAYBACK_PARAMETERS_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_PLAYBACK_PARAMETERS_CHANGED) TestUtil(com.google.android.exoplayer2.testutil.TestUtil) EVENT_VIDEO_SIZE_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_VIDEO_SIZE_CHANGED) ArrayList(java.util.ArrayList) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) EVENT_VIDEO_FRAME_PROCESSING_OFFSET(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_VIDEO_FRAME_PROCESSING_OFFSET) MediaDrmCallbackException(com.google.android.exoplayer2.drm.MediaDrmCallbackException) EVENT_DRM_SESSION_ACQUIRED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_DRM_SESSION_ACQUIRED) Clock(com.google.android.exoplayer2.util.Clock) ShadowLooper(org.robolectric.shadows.ShadowLooper) IOException(java.io.IOException) Test(org.junit.Test) EVENT_VIDEO_DISABLED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_VIDEO_DISABLED) TestPlayerRunHelper(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper) TracksInfo(com.google.android.exoplayer2.TracksInfo) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) DrmInitData(com.google.android.exoplayer2.drm.DrmInitData) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) Util(com.google.android.exoplayer2.util.Util) EVENT_VIDEO_ENABLED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_VIDEO_ENABLED) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) Player(com.google.android.exoplayer2.Player) EVENT_VIDEO_DECODER_INITIALIZED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_VIDEO_DECODER_INITIALIZED) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) ApplicationProvider(androidx.test.core.app.ApplicationProvider) Format(com.google.android.exoplayer2.Format) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EVENT_IS_LOADING_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_IS_LOADING_CHANGED) Method(java.lang.reflect.Method) MediaSource(com.google.android.exoplayer2.source.MediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) EVENT_PLAYER_RELEASED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_PLAYER_RELEASED) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) EVENT_PLAYBACK_STATE_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_PLAYBACK_STATE_CHANGED) MediaItem(com.google.android.exoplayer2.MediaItem) EVENT_DRM_KEYS_LOADED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_DRM_KEYS_LOADED) END_OF_STREAM_ITEM(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM) EVENT_TRACKS_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_TRACKS_CHANGED) UUID(java.util.UUID) EVENT_DRM_SESSION_MANAGER_ERROR(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_DRM_SESSION_MANAGER_ERROR) SparseArray(android.util.SparseArray) FakeSampleStreamItem.oneByteSample(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.oneByteSample) DrmSession(com.google.android.exoplayer2.drm.DrmSession) List(java.util.List) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Mockito.inOrder(org.mockito.Mockito.inOrder) EVENT_DRM_SESSION_RELEASED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_DRM_SESSION_RELEASED) PlaybackException(com.google.android.exoplayer2.PlaybackException) MediaLoadData(com.google.android.exoplayer2.source.MediaLoadData) FakeVideoRenderer(com.google.android.exoplayer2.testutil.FakeVideoRenderer) EVENT_AUDIO_POSITION_ADVANCING(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_AUDIO_POSITION_ADVANCING) Metadata(com.google.android.exoplayer2.metadata.Metadata) EVENT_LOAD_COMPLETED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_LOAD_COMPLETED) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DecoderCounters(com.google.android.exoplayer2.decoder.DecoderCounters) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) AtomicReference(java.util.concurrent.atomic.AtomicReference) EVENT_LOAD_ERROR(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_LOAD_ERROR) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) ConditionVariable(com.google.android.exoplayer2.util.ConditionVariable) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) VideoSize(com.google.android.exoplayer2.video.VideoSize) SurfaceTexture(android.graphics.SurfaceTexture) Window(com.google.android.exoplayer2.Timeline.Window) EVENT_MEDIA_ITEM_TRANSITION(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_MEDIA_ITEM_TRANSITION) MediaDrmCallback(com.google.android.exoplayer2.drm.MediaDrmCallback) InOrder(org.mockito.InOrder) Iterator(java.util.Iterator) EVENT_AUDIO_DISABLED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_AUDIO_DISABLED) EVENT_DOWNSTREAM_FORMAT_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_DOWNSTREAM_FORMAT_CHANGED) Truth.assertThat(com.google.common.truth.Truth.assertThat) EVENT_DROPPED_VIDEO_FRAMES(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_DROPPED_VIDEO_FRAMES) Mockito.verify(org.mockito.Mockito.verify) EVENT_PLAY_WHEN_READY_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_PLAY_WHEN_READY_CHANGED) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeExoMediaDrm(com.google.android.exoplayer2.testutil.FakeExoMediaDrm) EVENT_AUDIO_INPUT_FORMAT_CHANGED(com.google.android.exoplayer2.analytics.AnalyticsListener.EVENT_AUDIO_INPUT_FORMAT_CHANGED) Renderer(com.google.android.exoplayer2.Renderer) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeAudioRenderer(com.google.android.exoplayer2.testutil.FakeAudioRenderer) FakeVideoRenderer(com.google.android.exoplayer2.testutil.FakeVideoRenderer) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) Renderer(com.google.android.exoplayer2.Renderer) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) Test(org.junit.Test)

Example 23 with FakeRenderer

use of com.google.android.exoplayer2.testutil.FakeRenderer in project ExoPlayer by google.

the class ExoPlayerTest method renderersLifecycle_seekTo_resetsDisabledRenderersIfRequired.

@Test
public void renderersLifecycle_seekTo_resetsDisabledRenderersIfRequired() throws Exception {
    Timeline timeline = new FakeTimeline();
    final FakeRenderer audioRenderer = new FakeRenderer(C.TRACK_TYPE_AUDIO);
    final FakeRenderer videoRenderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    final FakeRenderer textRenderer = new FakeRenderer(C.TRACK_TYPE_TEXT);
    Format textFormat = new Format.Builder().setSampleMimeType(MimeTypes.TEXT_VTT).setLanguage("en").build();
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(videoRenderer, audioRenderer, textRenderer).build();
    Player.Listener mockPlayerListener = mock(Player.Listener.class);
    player.addListener(mockPlayerListener);
    player.setTrackSelectionParameters(player.getTrackSelectionParameters().buildUpon().setPreferredTextLanguage("en").build());
    player.setMediaSources(ImmutableList.of(new FakeMediaSource(timeline, ExoPlayerTestRunner.AUDIO_FORMAT), new FakeMediaSource(timeline, ExoPlayerTestRunner.AUDIO_FORMAT, textFormat)));
    player.prepare();
    player.play();
    runUntilPositionDiscontinuity(player, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
    // Disable text renderer by selecting a language that is not available.
    player.setTrackSelectionParameters(player.getTrackSelectionParameters().buildUpon().setPreferredTextLanguage("de").build());
    player.seekTo(/* mediaItemIndex= */
    0, /* positionMs= */
    1000);
    runUntilPlaybackState(player, Player.STATE_READY);
    // Expect formerly enabled renderers to be reset after seek.
    assertThat(textRenderer.resetCount).isEqualTo(1);
    assertThat(audioRenderer.resetCount).isEqualTo(0);
    assertThat(videoRenderer.resetCount).isEqualTo(0);
    runUntilPlaybackState(player, Player.STATE_ENDED);
    player.release();
    // Verify that the text renderer has not been reset a second time.
    assertThat(audioRenderer.enabledCount).isEqualTo(2);
    assertThat(audioRenderer.resetCount).isEqualTo(1);
    assertThat(textRenderer.enabledCount).isEqualTo(1);
    assertThat(textRenderer.resetCount).isEqualTo(1);
    assertThat(videoRenderer.enabledCount).isEqualTo(0);
    assertThat(videoRenderer.resetCount).isEqualTo(0);
}
Also used : FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) Listener(com.google.android.exoplayer2.Player.Listener) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 24 with FakeRenderer

use of com.google.android.exoplayer2.testutil.FakeRenderer in project ExoPlayer by google.

the class ExoPlayerTest method playEmptyTimeline.

/**
 * Tests playback of a source that exposes an empty timeline. Playback is expected to end without
 * error.
 */
@Test
public void playEmptyTimeline() throws Exception {
    Timeline timeline = Timeline.EMPTY;
    Timeline expectedMaskingTimeline = new MaskingMediaSource.PlaceholderTimeline(FakeMediaSource.FAKE_MEDIA_ITEM);
    FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_UNKNOWN);
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(renderer).build();
    Player.Listener mockListener = mock(Player.Listener.class);
    player.addListener(mockListener);
    player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT));
    player.prepare();
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    InOrder inOrder = inOrder(mockListener);
    inOrder.verify(mockListener).onTimelineChanged(argThat(noUid(expectedMaskingTimeline)), eq(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED));
    inOrder.verify(mockListener).onTimelineChanged(argThat(noUid(timeline)), eq(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE));
    inOrder.verify(mockListener, never()).onPositionDiscontinuity(anyInt());
    inOrder.verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt());
    assertThat(renderer.getFormatsRead()).isEmpty();
    assertThat(renderer.sampleBufferReadCount).isEqualTo(0);
    assertThat(renderer.isEnded).isFalse();
}
Also used : FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) Listener(com.google.android.exoplayer2.Player.Listener) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) InOrder(org.mockito.InOrder) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 25 with FakeRenderer

use of com.google.android.exoplayer2.testutil.FakeRenderer in project ExoPlayer by google.

the class ExoPlayerTest method renderersLifecycle_renderersThatAreNeverEnabled_areNotReset.

@Test
public void renderersLifecycle_renderersThatAreNeverEnabled_areNotReset() throws Exception {
    Timeline timeline = new FakeTimeline();
    final FakeRenderer videoRenderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    final FakeRenderer audioRenderer = new FakeRenderer(C.TRACK_TYPE_AUDIO);
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(videoRenderer, audioRenderer).build();
    Player.Listener mockPlayerListener = mock(Player.Listener.class);
    player.addListener(mockPlayerListener);
    player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.AUDIO_FORMAT));
    player.prepare();
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    player.release();
    assertThat(audioRenderer.enabledCount).isEqualTo(1);
    assertThat(audioRenderer.resetCount).isEqualTo(1);
    assertThat(videoRenderer.enabledCount).isEqualTo(0);
    assertThat(videoRenderer.resetCount).isEqualTo(0);
}
Also used : FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) Listener(com.google.android.exoplayer2.Player.Listener) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Aggregations

FakeRenderer (com.google.android.exoplayer2.testutil.FakeRenderer)27 Test (org.junit.Test)27 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)25 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)25 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)24 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)17 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)17 MediaSource (com.google.android.exoplayer2.source.MediaSource)16 Listener (com.google.android.exoplayer2.Player.Listener)12 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)12 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)11 InOrder (org.mockito.InOrder)11 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)10 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)10 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)9 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)9 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)9 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)9 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)9 Nullable (androidx.annotation.Nullable)8