Search in sources :

Example 6 with AudioRendererEventListener

use of com.google.android.exoplayer2.audio.AudioRendererEventListener in project ExoPlayer by google.

the class MediaCodecAudioRendererTest method render_callsAudioRendererEventListener_whenAudioSinkListenerOnAudioSinkErrorIsCalled.

@Test
public void render_callsAudioRendererEventListener_whenAudioSinkListenerOnAudioSinkErrorIsCalled() {
    final ArgumentCaptor<AudioSink.Listener> listenerCaptor = ArgumentCaptor.forClass(AudioSink.Listener.class);
    verify(audioSink, atLeastOnce()).setListener(listenerCaptor.capture());
    AudioSink.Listener audioSinkListener = listenerCaptor.getValue();
    Exception error = new AudioSink.WriteException(/* errorCode= */
    1, new Format.Builder().build(), /* isRecoverable= */
    true);
    audioSinkListener.onAudioSinkError(error);
    shadowOf(Looper.getMainLooper()).idle();
    verify(audioRendererEventListener).onAudioSinkError(error);
}
Also used : DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException) PlaybackException(com.google.android.exoplayer2.PlaybackException) Test(org.junit.Test)

Example 7 with AudioRendererEventListener

use of com.google.android.exoplayer2.audio.AudioRendererEventListener in project ExoPlayer by google.

the class MediaCodecAudioRendererTest method supportsFormat_withEac3JocMediaAndEac3Decoder_returnsTrue.

@Test
public void supportsFormat_withEac3JocMediaAndEac3Decoder_returnsTrue() throws Exception {
    Format mediaFormat = new Format.Builder().setSampleMimeType(MimeTypes.AUDIO_E_AC3_JOC).setCodecs(MimeTypes.CODEC_E_AC3_JOC).build();
    MediaCodecSelector mediaCodecSelector = (mimeType, requiresSecureDecoder, requiresTunnelingDecoder) -> !mimeType.equals(MimeTypes.AUDIO_E_AC3) ? ImmutableList.of() : ImmutableList.of(MediaCodecInfo.newInstance(/* name= */
    "eac3-codec", /* mimeType= */
    mimeType, /* codecMimeType= */
    mimeType, /* capabilities= */
    null, /* hardwareAccelerated= */
    false, /* softwareOnly= */
    true, /* vendor= */
    false, /* forceDisableAdaptive= */
    false, /* forceSecure= */
    false));
    MediaCodecAudioRenderer renderer = new MediaCodecAudioRenderer(ApplicationProvider.getApplicationContext(), mediaCodecSelector, /* enableDecoderFallback= */
    false, /* eventHandler= */
    new Handler(Looper.getMainLooper()), audioRendererEventListener, audioSink);
    renderer.init(/* index= */
    0, PlayerId.UNSET);
    @Capabilities int capabilities = renderer.supportsFormat(mediaFormat);
    assertThat(RendererCapabilities.getFormatSupport(capabilities)).isEqualTo(C.FORMAT_HANDLED);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) MediaFormat(android.media.MediaFormat) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Mock(org.mockito.Mock) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) SystemClock(android.os.SystemClock) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) Shadows.shadowOf(org.robolectric.Shadows.shadowOf) ApplicationProvider(androidx.test.core.app.ApplicationProvider) Format(com.google.android.exoplayer2.Format) PlayerId(com.google.android.exoplayer2.analytics.PlayerId) MediaCodecInfo(com.google.android.exoplayer2.mediacodec.MediaCodecInfo) ArgumentCaptor(org.mockito.ArgumentCaptor) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) MimeTypes(com.google.android.exoplayer2.util.MimeTypes) ImmutableList(com.google.common.collect.ImmutableList) Handler(android.os.Handler) Looper(android.os.Looper) MockitoJUnit(org.mockito.junit.MockitoJUnit) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) FakeSampleStream(com.google.android.exoplayer2.testutil.FakeSampleStream) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) C(com.google.android.exoplayer2.C) Before(org.junit.Before) FakeSampleStreamItem.format(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.format) Capabilities(com.google.android.exoplayer2.RendererCapabilities.Capabilities) END_OF_STREAM_ITEM(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) Mockito.verify(org.mockito.Mockito.verify) FakeSampleStreamItem.oneByteSample(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.oneByteSample) Nullable(androidx.annotation.Nullable) Rule(org.junit.Rule) RendererConfiguration(com.google.android.exoplayer2.RendererConfiguration) MediaCodecSelector(com.google.android.exoplayer2.mediacodec.MediaCodecSelector) PlaybackException(com.google.android.exoplayer2.PlaybackException) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) MockitoRule(org.mockito.junit.MockitoRule) Collections(java.util.Collections) MediaCodecSelector(com.google.android.exoplayer2.mediacodec.MediaCodecSelector) MediaFormat(android.media.MediaFormat) Format(com.google.android.exoplayer2.Format) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Capabilities(com.google.android.exoplayer2.RendererCapabilities.Capabilities) Handler(android.os.Handler) Test(org.junit.Test)

Example 8 with AudioRendererEventListener

use of com.google.android.exoplayer2.audio.AudioRendererEventListener in project ExoPlayer by google.

the class TestExoPlayerBuilder method build.

/**
 * Builds an {@link ExoPlayer} using the provided values or their defaults.
 */
public ExoPlayer build() {
    Assertions.checkNotNull(looper, "TestExoPlayer builder run on a thread without Looper and no Looper specified.");
    // Do not update renderersFactory and renderers here, otherwise their getters may
    // return different values before and after build() is called, making them confusing.
    RenderersFactory playerRenderersFactory = renderersFactory;
    if (playerRenderersFactory == null) {
        playerRenderersFactory = (eventHandler, videoRendererEventListener, audioRendererEventListener, textRendererOutput, metadataRendererOutput) -> renderers != null ? renderers : new Renderer[] { new FakeVideoRenderer(eventHandler, videoRendererEventListener), new FakeAudioRenderer(eventHandler, audioRendererEventListener) };
    }
    ExoPlayer.Builder builder = new ExoPlayer.Builder(context, playerRenderersFactory).setTrackSelector(trackSelector).setLoadControl(loadControl).setBandwidthMeter(bandwidthMeter).setAnalyticsCollector(new DefaultAnalyticsCollector(clock)).setClock(clock).setUseLazyPreparation(useLazyPreparation).setLooper(looper).setSeekBackIncrementMs(seekBackIncrementMs).setSeekForwardIncrementMs(seekForwardIncrementMs);
    if (mediaSourceFactory != null) {
        builder.setMediaSourceFactory(mediaSourceFactory);
    }
    return builder.build();
}
Also used : Renderer(com.google.android.exoplayer2.Renderer) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) DefaultAnalyticsCollector(com.google.android.exoplayer2.analytics.DefaultAnalyticsCollector)

Aggregations

MediaCodecAudioRenderer (com.google.android.exoplayer2.audio.MediaCodecAudioRenderer)3 MetadataRenderer (com.google.android.exoplayer2.metadata.MetadataRenderer)3 TextRenderer (com.google.android.exoplayer2.text.TextRenderer)3 MediaCodecVideoRenderer (com.google.android.exoplayer2.video.MediaCodecVideoRenderer)3 MediaFormat (android.media.MediaFormat)2 Handler (android.os.Handler)2 Nullable (androidx.annotation.Nullable)2 ExoPlaybackException (com.google.android.exoplayer2.ExoPlaybackException)2 Format (com.google.android.exoplayer2.Format)2 PlaybackException (com.google.android.exoplayer2.PlaybackException)2 Renderer (com.google.android.exoplayer2.Renderer)2 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)2 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)2 CameraMotionRenderer (com.google.android.exoplayer2.video.spherical.CameraMotionRenderer)2 Before (org.junit.Before)2 Test (org.junit.Test)2 Looper (android.os.Looper)1 SystemClock (android.os.SystemClock)1 ApplicationProvider (androidx.test.core.app.ApplicationProvider)1 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)1