Search in sources :

Example 1 with MediaCodecAudioRenderer

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

the class SimpleExoPlayer method buildAudioRenderers.

/**
   * Builds audio renderers for use by the player.
   *
   * @param context The {@link Context} associated with the player.
   * @param mainHandler A handler associated with the main thread's looper.
   * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the player will
   *     not be used for DRM protected playbacks.
   * @param extensionRendererMode The extension renderer mode.
   * @param eventListener An event listener.
   * @param audioProcessors An array of {@link AudioProcessor}s that will process PCM audio buffers
   *     before output. May be empty.
   * @param out An array to which the built renderers should be appended.
   */
protected void buildAudioRenderers(Context context, Handler mainHandler, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, @ExtensionRendererMode int extensionRendererMode, AudioRendererEventListener eventListener, AudioProcessor[] audioProcessors, ArrayList<Renderer> out) {
    out.add(new MediaCodecAudioRenderer(MediaCodecSelector.DEFAULT, drmSessionManager, true, mainHandler, eventListener, AudioCapabilities.getCapabilities(context), audioProcessors));
    if (extensionRendererMode == EXTENSION_RENDERER_MODE_OFF) {
        return;
    }
    int extensionRendererIndex = out.size();
    if (extensionRendererMode == EXTENSION_RENDERER_MODE_PREFER) {
        extensionRendererIndex--;
    }
    try {
        Class<?> clazz = Class.forName("com.google.android.exoplayer2.ext.opus.LibopusAudioRenderer");
        Constructor<?> constructor = clazz.getConstructor(Handler.class, AudioRendererEventListener.class, AudioProcessor[].class);
        Renderer renderer = (Renderer) constructor.newInstance(mainHandler, componentListener, audioProcessors);
        out.add(extensionRendererIndex++, renderer);
        Log.i(TAG, "Loaded LibopusAudioRenderer.");
    } catch (ClassNotFoundException e) {
    // Expected if the app was built without the extension.
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    try {
        Class<?> clazz = Class.forName("com.google.android.exoplayer2.ext.flac.LibflacAudioRenderer");
        Constructor<?> constructor = clazz.getConstructor(Handler.class, AudioRendererEventListener.class, AudioProcessor[].class);
        Renderer renderer = (Renderer) constructor.newInstance(mainHandler, componentListener, audioProcessors);
        out.add(extensionRendererIndex++, renderer);
        Log.i(TAG, "Loaded LibflacAudioRenderer.");
    } catch (ClassNotFoundException e) {
    // Expected if the app was built without the extension.
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    try {
        Class<?> clazz = Class.forName("com.google.android.exoplayer2.ext.ffmpeg.FfmpegAudioRenderer");
        Constructor<?> constructor = clazz.getConstructor(Handler.class, AudioRendererEventListener.class, AudioProcessor[].class);
        Renderer renderer = (Renderer) constructor.newInstance(mainHandler, componentListener, audioProcessors);
        out.add(extensionRendererIndex++, renderer);
        Log.i(TAG, "Loaded FfmpegAudioRenderer.");
    } catch (ClassNotFoundException e) {
    // Expected if the app was built without the extension.
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : AudioProcessor(com.google.android.exoplayer2.audio.AudioProcessor) MediaCodecAudioRenderer(com.google.android.exoplayer2.audio.MediaCodecAudioRenderer) MediaCodecAudioRenderer(com.google.android.exoplayer2.audio.MediaCodecAudioRenderer) MetadataRenderer(com.google.android.exoplayer2.metadata.MetadataRenderer) MediaCodecVideoRenderer(com.google.android.exoplayer2.video.MediaCodecVideoRenderer) TextRenderer(com.google.android.exoplayer2.text.TextRenderer)

Aggregations

AudioProcessor (com.google.android.exoplayer2.audio.AudioProcessor)1 MediaCodecAudioRenderer (com.google.android.exoplayer2.audio.MediaCodecAudioRenderer)1 MetadataRenderer (com.google.android.exoplayer2.metadata.MetadataRenderer)1 TextRenderer (com.google.android.exoplayer2.text.TextRenderer)1 MediaCodecVideoRenderer (com.google.android.exoplayer2.video.MediaCodecVideoRenderer)1