Search in sources :

Example 1 with TextRenderer

use of androidx.media3.exoplayer.text.TextRenderer in project media by androidx.

the class DownloadHelperTest method setUp.

@Before
public void setUp() {
    FakeRenderer videoRenderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    FakeRenderer audioRenderer = new FakeRenderer(C.TRACK_TYPE_AUDIO);
    FakeRenderer textRenderer = new FakeRenderer(C.TRACK_TYPE_TEXT);
    RenderersFactory renderersFactory = (handler, videoListener, audioListener, metadata, text) -> new Renderer[] { textRenderer, audioRenderer, videoRenderer };
    downloadHelper = new DownloadHelper(testMediaItem, new TestMediaSource(), DownloadHelper.DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXT, DownloadHelper.getRendererCapabilities(renderersFactory));
}
Also used : FakeRenderer(androidx.media3.test.utils.FakeRenderer) TrackGroup(androidx.media3.common.TrackGroup) Arrays(java.util.Arrays) StreamKey(androidx.media3.common.StreamKey) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) MappedTrackInfo(androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo) Allocator(androidx.media3.exoplayer.upstream.Allocator) DefaultTrackSelector(androidx.media3.exoplayer.trackselection.DefaultTrackSelector) FakeTimeline(androidx.media3.test.utils.FakeTimeline) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) AtomicReference(java.util.concurrent.atomic.AtomicReference) ShadowLooper.shadowMainLooper(org.robolectric.shadows.ShadowLooper.shadowMainLooper) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ArrayList(java.util.ArrayList) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) Renderer(androidx.media3.exoplayer.Renderer) Callback(androidx.media3.exoplayer.offline.DownloadHelper.Callback) MediaItem(androidx.media3.common.MediaItem) RenderersFactory(androidx.media3.exoplayer.RenderersFactory) Before(org.junit.Before) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) MimeTypes(androidx.media3.common.MimeTypes) ExoTrackSelection(androidx.media3.exoplayer.trackselection.ExoTrackSelection) EventDispatcher(androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher) IOException(java.io.IOException) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Truth.assertThat(com.google.common.truth.Truth.assertThat) TrackGroupArray(androidx.media3.common.TrackGroupArray) Format(androidx.media3.common.Format) FakeMediaPeriod(androidx.media3.test.utils.FakeMediaPeriod) C(androidx.media3.common.C) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Timeline(androidx.media3.common.Timeline) FakeRenderer(androidx.media3.test.utils.FakeRenderer) MediaPeriod(androidx.media3.exoplayer.source.MediaPeriod) Renderer(androidx.media3.exoplayer.Renderer) FakeRenderer(androidx.media3.test.utils.FakeRenderer) RenderersFactory(androidx.media3.exoplayer.RenderersFactory) Before(org.junit.Before)

Example 2 with TextRenderer

use of androidx.media3.exoplayer.text.TextRenderer in project media by androidx.

the class ExoPlayerTest method renderersLifecycle_setForegroundMode_resetsDisabledRenderersThatHaveBeenEnabled.

@Test
public void renderersLifecycle_setForegroundMode_resetsDisabledRenderersThatHaveBeenEnabled() throws Exception {
    Timeline timeline = new FakeTimeline();
    final FakeRenderer videoRenderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    final FakeRenderer audioRenderer = new FakeRenderer(C.TRACK_TYPE_AUDIO);
    final FakeRenderer textRenderer = new FakeRenderer(C.TRACK_TYPE_TEXT);
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(videoRenderer, audioRenderer).build();
    Player.Listener mockPlayerListener = mock(Player.Listener.class);
    player.addListener(mockPlayerListener);
    player.setMediaSources(ImmutableList.of(new FakeMediaSource(timeline, ExoPlayerTestRunner.AUDIO_FORMAT, ExoPlayerTestRunner.VIDEO_FORMAT), new FakeMediaSource(timeline, ExoPlayerTestRunner.AUDIO_FORMAT)));
    player.prepare();
    player.play();
    runUntilPositionDiscontinuity(player, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
    player.setForegroundMode(/* foregroundMode= */
    true);
    // Only the video renderer that is disabled in the second media item has been reset.
    assertThat(audioRenderer.resetCount).isEqualTo(0);
    assertThat(videoRenderer.resetCount).isEqualTo(1);
    runUntilPlaybackState(player, Player.STATE_ENDED);
    player.release();
    // After release the audio renderer is reset as well.
    assertThat(audioRenderer.enabledCount).isEqualTo(1);
    assertThat(audioRenderer.resetCount).isEqualTo(1);
    assertThat(videoRenderer.enabledCount).isEqualTo(1);
    assertThat(videoRenderer.resetCount).isEqualTo(1);
    assertThat(textRenderer.enabledCount).isEqualTo(0);
    assertThat(textRenderer.resetCount).isEqualTo(0);
}
Also used : FakeRenderer(androidx.media3.test.utils.FakeRenderer) Listener(androidx.media3.common.Player.Listener) Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) Player(androidx.media3.common.Player) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 3 with TextRenderer

use of androidx.media3.exoplayer.text.TextRenderer in project media by androidx.

the class ExoPlayerTest method renderersLifecycle_selectTextTracksWhilePlaying_textRendererEnabledAndReset.

@Test
public void renderersLifecycle_selectTextTracksWhilePlaying_textRendererEnabledAndReset() 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(audioRenderer, textRenderer).build();
    Player.Listener mockPlayerListener = mock(Player.Listener.class);
    player.addListener(mockPlayerListener);
    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);
    // Only the audio renderer enabled so far.
    assertThat(audioRenderer.enabledCount).isEqualTo(1);
    assertThat(textRenderer.enabledCount).isEqualTo(0);
    player.setTrackSelectionParameters(player.getTrackSelectionParameters().buildUpon().setPreferredTextLanguage("en").build());
    runUntilPlaybackState(player, Player.STATE_ENDED);
    player.release();
    assertThat(audioRenderer.enabledCount).isEqualTo(1);
    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(androidx.media3.test.utils.FakeRenderer) Listener(androidx.media3.common.Player.Listener) Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) Player(androidx.media3.common.Player) Format(androidx.media3.common.Format) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Example 4 with TextRenderer

use of androidx.media3.exoplayer.text.TextRenderer in project media by androidx.

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(androidx.media3.test.utils.FakeRenderer) Listener(androidx.media3.common.Player.Listener) Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) Player(androidx.media3.common.Player) Format(androidx.media3.common.Format) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Test(org.junit.Test)

Aggregations

Timeline (androidx.media3.common.Timeline)4 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)4 FakeRenderer (androidx.media3.test.utils.FakeRenderer)4 FakeTimeline (androidx.media3.test.utils.FakeTimeline)4 Test (org.junit.Test)4 Format (androidx.media3.common.Format)3 Player (androidx.media3.common.Player)3 Listener (androidx.media3.common.Player.Listener)3 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)3 NoUidTimeline (androidx.media3.test.utils.NoUidTimeline)3 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)3 C (androidx.media3.common.C)1 MediaItem (androidx.media3.common.MediaItem)1 MimeTypes (androidx.media3.common.MimeTypes)1 StreamKey (androidx.media3.common.StreamKey)1 TrackGroup (androidx.media3.common.TrackGroup)1 TrackGroupArray (androidx.media3.common.TrackGroupArray)1 Renderer (androidx.media3.exoplayer.Renderer)1 RenderersFactory (androidx.media3.exoplayer.RenderersFactory)1 Callback (androidx.media3.exoplayer.offline.DownloadHelper.Callback)1