Search in sources :

Example 1 with VideoRendererEventListener

use of androidx.media3.exoplayer.video.VideoRendererEventListener in project media by androidx.

the class DownloadHelper method getRendererCapabilities.

/**
 * Extracts renderer capabilities for the renderers created by the provided renderers factory.
 *
 * @param renderersFactory A {@link RenderersFactory}.
 * @return The {@link RendererCapabilities} for each renderer created by the {@code
 *     renderersFactory}.
 */
public static RendererCapabilities[] getRendererCapabilities(RenderersFactory renderersFactory) {
    Renderer[] renderers = renderersFactory.createRenderers(Util.createHandlerForCurrentOrMainLooper(), new VideoRendererEventListener() {
    }, new AudioRendererEventListener() {
    }, (cues) -> {
    }, (metadata) -> {
    });
    RendererCapabilities[] capabilities = new RendererCapabilities[renderers.length];
    for (int i = 0; i < renderers.length; i++) {
        capabilities[i] = renderers[i].getCapabilities();
    }
    return capabilities;
}
Also used : Renderer(androidx.media3.exoplayer.Renderer) VideoRendererEventListener(androidx.media3.exoplayer.video.VideoRendererEventListener) AudioRendererEventListener(androidx.media3.exoplayer.audio.AudioRendererEventListener) RendererCapabilities(androidx.media3.exoplayer.RendererCapabilities)

Example 2 with VideoRendererEventListener

use of androidx.media3.exoplayer.video.VideoRendererEventListener in project media by androidx.

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(androidx.media3.exoplayer.Renderer) RenderersFactory(androidx.media3.exoplayer.RenderersFactory) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) DefaultAnalyticsCollector(androidx.media3.exoplayer.analytics.DefaultAnalyticsCollector)

Example 3 with VideoRendererEventListener

use of androidx.media3.exoplayer.video.VideoRendererEventListener in project media by androidx.

the class DefaultRenderersFactory method createRenderers.

@Override
public Renderer[] createRenderers(Handler eventHandler, VideoRendererEventListener videoRendererEventListener, AudioRendererEventListener audioRendererEventListener, TextOutput textRendererOutput, MetadataOutput metadataRendererOutput) {
    ArrayList<Renderer> renderersList = new ArrayList<>();
    buildVideoRenderers(context, extensionRendererMode, mediaCodecSelector, enableDecoderFallback, eventHandler, videoRendererEventListener, allowedVideoJoiningTimeMs, renderersList);
    @Nullable AudioSink audioSink = buildAudioSink(context, enableFloatOutput, enableAudioTrackPlaybackParams, enableOffload);
    if (audioSink != null) {
        buildAudioRenderers(context, extensionRendererMode, mediaCodecSelector, enableDecoderFallback, audioSink, eventHandler, audioRendererEventListener, renderersList);
    }
    buildTextRenderers(context, textRendererOutput, eventHandler.getLooper(), extensionRendererMode, renderersList);
    buildMetadataRenderers(context, metadataRendererOutput, eventHandler.getLooper(), extensionRendererMode, renderersList);
    buildCameraMotionRenderers(context, extensionRendererMode, renderersList);
    buildMiscellaneousRenderers(context, eventHandler, extensionRendererMode, renderersList);
    return renderersList.toArray(new Renderer[0]);
}
Also used : AudioSink(androidx.media3.exoplayer.audio.AudioSink) DefaultAudioSink(androidx.media3.exoplayer.audio.DefaultAudioSink) MediaCodecAudioRenderer(androidx.media3.exoplayer.audio.MediaCodecAudioRenderer) TextRenderer(androidx.media3.exoplayer.text.TextRenderer) MediaCodecVideoRenderer(androidx.media3.exoplayer.video.MediaCodecVideoRenderer) CameraMotionRenderer(androidx.media3.exoplayer.video.spherical.CameraMotionRenderer) MetadataRenderer(androidx.media3.exoplayer.metadata.MetadataRenderer) ArrayList(java.util.ArrayList) Nullable(androidx.annotation.Nullable)

Example 4 with VideoRendererEventListener

use of androidx.media3.exoplayer.video.VideoRendererEventListener in project media by androidx.

the class DefaultRenderersFactory method buildVideoRenderers.

/**
 * Builds video renderers for use by the player.
 *
 * @param context The {@link Context} associated with the player.
 * @param extensionRendererMode The extension renderer mode.
 * @param mediaCodecSelector A decoder selector.
 * @param enableDecoderFallback Whether to enable fallback to lower-priority decoders if decoder
 *     initialization fails. This may result in using a decoder that is slower/less efficient than
 *     the primary decoder.
 * @param eventHandler A handler associated with the main thread's looper.
 * @param eventListener An event listener.
 * @param allowedVideoJoiningTimeMs The maximum duration for which video renderers can attempt to
 *     seamlessly join an ongoing playback, in milliseconds.
 * @param out An array to which the built renderers should be appended.
 */
protected void buildVideoRenderers(Context context, @ExtensionRendererMode int extensionRendererMode, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, Handler eventHandler, VideoRendererEventListener eventListener, long allowedVideoJoiningTimeMs, ArrayList<Renderer> out) {
    MediaCodecVideoRenderer videoRenderer = new MediaCodecVideoRenderer(context, getCodecAdapterFactory(), mediaCodecSelector, allowedVideoJoiningTimeMs, enableDecoderFallback, eventHandler, eventListener, MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY);
    out.add(videoRenderer);
    if (extensionRendererMode == EXTENSION_RENDERER_MODE_OFF) {
        return;
    }
    int extensionRendererIndex = out.size();
    if (extensionRendererMode == EXTENSION_RENDERER_MODE_PREFER) {
        extensionRendererIndex--;
    }
    try {
        // Full class names used for constructor args so the LINT rule triggers if any of them move.
        Class<?> clazz = Class.forName("androidx.media3.decoder.vp9.LibvpxVideoRenderer");
        Constructor<?> constructor = clazz.getConstructor(long.class, android.os.Handler.class, androidx.media3.exoplayer.video.VideoRendererEventListener.class, int.class);
        Renderer renderer = (Renderer) constructor.newInstance(allowedVideoJoiningTimeMs, eventHandler, eventListener, MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY);
        out.add(extensionRendererIndex++, renderer);
        Log.i(TAG, "Loaded LibvpxVideoRenderer.");
    } catch (ClassNotFoundException e) {
    // Expected if the app was built without the extension.
    } catch (Exception e) {
        // The extension is present, but instantiation failed.
        throw new RuntimeException("Error instantiating VP9 extension", e);
    }
    try {
        // Full class names used for constructor args so the LINT rule triggers if any of them move.
        Class<?> clazz = Class.forName("androidx.media3.decoder.av1.Libgav1VideoRenderer");
        Constructor<?> constructor = clazz.getConstructor(long.class, android.os.Handler.class, androidx.media3.exoplayer.video.VideoRendererEventListener.class, int.class);
        Renderer renderer = (Renderer) constructor.newInstance(allowedVideoJoiningTimeMs, eventHandler, eventListener, MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY);
        out.add(extensionRendererIndex++, renderer);
        Log.i(TAG, "Loaded Libgav1VideoRenderer.");
    } catch (ClassNotFoundException e) {
    // Expected if the app was built without the extension.
    } catch (Exception e) {
        // The extension is present, but instantiation failed.
        throw new RuntimeException("Error instantiating AV1 extension", e);
    }
}
Also used : MediaCodecVideoRenderer(androidx.media3.exoplayer.video.MediaCodecVideoRenderer) MediaCodecAudioRenderer(androidx.media3.exoplayer.audio.MediaCodecAudioRenderer) TextRenderer(androidx.media3.exoplayer.text.TextRenderer) MediaCodecVideoRenderer(androidx.media3.exoplayer.video.MediaCodecVideoRenderer) CameraMotionRenderer(androidx.media3.exoplayer.video.spherical.CameraMotionRenderer) MetadataRenderer(androidx.media3.exoplayer.metadata.MetadataRenderer)

Aggregations

Renderer (androidx.media3.exoplayer.Renderer)2 MediaCodecAudioRenderer (androidx.media3.exoplayer.audio.MediaCodecAudioRenderer)2 MetadataRenderer (androidx.media3.exoplayer.metadata.MetadataRenderer)2 TextRenderer (androidx.media3.exoplayer.text.TextRenderer)2 MediaCodecVideoRenderer (androidx.media3.exoplayer.video.MediaCodecVideoRenderer)2 CameraMotionRenderer (androidx.media3.exoplayer.video.spherical.CameraMotionRenderer)2 Nullable (androidx.annotation.Nullable)1 ExoPlayer (androidx.media3.exoplayer.ExoPlayer)1 RendererCapabilities (androidx.media3.exoplayer.RendererCapabilities)1 RenderersFactory (androidx.media3.exoplayer.RenderersFactory)1 DefaultAnalyticsCollector (androidx.media3.exoplayer.analytics.DefaultAnalyticsCollector)1 AudioRendererEventListener (androidx.media3.exoplayer.audio.AudioRendererEventListener)1 AudioSink (androidx.media3.exoplayer.audio.AudioSink)1 DefaultAudioSink (androidx.media3.exoplayer.audio.DefaultAudioSink)1 VideoRendererEventListener (androidx.media3.exoplayer.video.VideoRendererEventListener)1 ArrayList (java.util.ArrayList)1