com.google.android.exoplayer2.audio.AudioRendererEventListener Java Examples

The following examples show how to use com.google.android.exoplayer2.audio.AudioRendererEventListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RendererProvider.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
@NonNull
protected List<Renderer> buildAudioRenderers() {
    List<Renderer> renderers = new ArrayList<>();
    renderers.add(new MediaCodecAudioRenderer(context, MediaCodecSelector.DEFAULT, drmSessionManager, true, handler, audioRendererEventListener, AudioCapabilities.getCapabilities(context)));

    // Adds any registered classes
    List<String> classNames = ExoMedia.Data.registeredRendererClasses.get(ExoMedia.RendererType.AUDIO);
    if (classNames != null) {
        for (String className: classNames) {
            try {
                Class<?> clazz = Class.forName(className);
                Constructor<?> constructor = clazz.getConstructor(Handler.class, AudioRendererEventListener.class);
                Renderer renderer = (Renderer) constructor.newInstance(handler, audioRendererEventListener);
                renderers.add(renderer);
            } catch (Exception e) {
                // Purposefully left blank
            }
        }
    }

    return renderers;
}
 
Example #2
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onAudioSessionId(int sessionId) {
  if (audioSessionId == sessionId) {
    return;
  }
  audioSessionId = sessionId;
  for (AudioListener audioListener : audioListeners) {
    // Prevent duplicate notification if a listener is both a AudioRendererEventListener and
    // a AudioListener, as they have the same method signature.
    if (!audioDebugListeners.contains(audioListener)) {
      audioListener.onAudioSessionId(sessionId);
    }
  }
  for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
    audioDebugListener.onAudioSessionId(sessionId);
  }
}
 
Example #3
Source File: Util.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Extract renderer capabilities for the renderers created by the provided renderers factory.
 *
 * @param renderersFactory A {@link RenderersFactory}.
 * @param drmSessionManager An optional {@link DrmSessionManager} used by the renderers.
 * @return The {@link RendererCapabilities} for each renderer created by the {@code
 *     renderersFactory}.
 */
public static RendererCapabilities[] getRendererCapabilities(
    RenderersFactory renderersFactory,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
  Renderer[] renderers =
      renderersFactory.createRenderers(
          new Handler(),
          new VideoRendererEventListener() {},
          new AudioRendererEventListener() {},
          (cues) -> {},
          (metadata) -> {},
          drmSessionManager);
  RendererCapabilities[] capabilities = new RendererCapabilities[renderers.length];
  for (int i = 0; i < renderers.length; i++) {
    capabilities[i] = renderers[i].getCapabilities();
  }
  return capabilities;
}
 
Example #4
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onAudioSessionId(int sessionId) {
  if (audioSessionId == sessionId) {
    return;
  }
  audioSessionId = sessionId;
  for (AudioListener audioListener : audioListeners) {
    // Prevent duplicate notification if a listener is both a AudioRendererEventListener and
    // a AudioListener, as they have the same method signature.
    if (!audioDebugListeners.contains(audioListener)) {
      audioListener.onAudioSessionId(sessionId);
    }
  }
  for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
    audioDebugListener.onAudioSessionId(sessionId);
  }
}
 
Example #5
Source File: DefaultRenderersFactory.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Renderer[] createRenderers(
    Handler eventHandler,
    VideoRendererEventListener videoRendererEventListener,
    AudioRendererEventListener audioRendererEventListener,
    TextOutput textRendererOutput,
    MetadataOutput metadataRendererOutput,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
  if (drmSessionManager == null) {
    drmSessionManager = this.drmSessionManager;
  }
  ArrayList<Renderer> renderersList = new ArrayList<>();
  buildVideoRenderers(context, drmSessionManager, allowedVideoJoiningTimeMs,
      eventHandler, videoRendererEventListener, extensionRendererMode, renderersList);
  buildAudioRenderers(context, drmSessionManager, buildAudioProcessors(),
      eventHandler, audioRendererEventListener, extensionRendererMode, renderersList);
  buildTextRenderers(context, textRendererOutput, eventHandler.getLooper(),
      extensionRendererMode, renderersList);
  buildMetadataRenderers(context, metadataRendererOutput, eventHandler.getLooper(),
      extensionRendererMode, renderersList);
  buildMiscellaneousRenderers(context, eventHandler, extensionRendererMode, renderersList);
  return renderersList.toArray(new Renderer[renderersList.size()]);
}
 
Example #6
Source File: SimpleExoPlayer.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onAudioSessionId(int sessionId) {
  if (audioSessionId == sessionId) {
    return;
  }
  audioSessionId = sessionId;
  for (AudioListener audioListener : audioListeners) {
    // Prevent duplicate notification if a listener is both a AudioRendererEventListener and
    // a AudioListener, as they have the same method signature.
    if (!audioDebugListeners.contains(audioListener)) {
      audioListener.onAudioSessionId(sessionId);
    }
  }
  for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
    audioDebugListener.onAudioSessionId(sessionId);
  }
}
 
Example #7
Source File: ExoplayerAudioRenderer.java    From lbry-android with MIT License 6 votes vote down vote up
@Override
protected void buildAudioRenderers(
        Context context,
        int extensionRendererMode,
        MediaCodecSelector mediaCodecSelector,
        @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
        boolean playClearSamplesWithoutKeys,
        boolean enableDecoderFallback,
        AudioProcessor[] audioProcessors,
        Handler eventHandler,
        AudioRendererEventListener eventListener,
        ArrayList<Renderer> out) {
    AudioProcessor[] audioProcessorList = { new TeeAudioProcessor(audioBufferSink) };
    super.buildAudioRenderers(
            context,
            extensionRendererMode,
            mediaCodecSelector,
            drmSessionManager,
            playClearSamplesWithoutKeys,
            enableDecoderFallback,
            audioProcessorList,
            eventHandler,
            eventListener,
            out);
}
 
Example #8
Source File: SimpleRenderersFactory.java    From no-player with Apache License 2.0 6 votes vote down vote up
@Override
public Renderer[] createRenderers(Handler eventHandler,
                                  VideoRendererEventListener videoRendererEventListener,
                                  AudioRendererEventListener audioRendererEventListener,
                                  TextOutput textRendererOutput,
                                  MetadataOutput metadataRendererOutput,
                                  @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
    ArrayList<Renderer> renderersList = new ArrayList<>();
    buildVideoRenderers(context, drmSessionManager, allowedVideoJoiningTimeMs,
            eventHandler, videoRendererEventListener, extensionRendererMode, renderersList);
    buildAudioRenderers(context, drmSessionManager, buildAudioProcessors(),
            eventHandler, audioRendererEventListener, extensionRendererMode, renderersList);
    buildTextRenderers(textRendererOutput, eventHandler.getLooper(), renderersList, subtitleDecoderFactory);
    buildMetadataRenderers(metadataRendererOutput, eventHandler.getLooper(),
            renderersList);
    buildMiscellaneousRenderers();
    return renderersList.toArray(new Renderer[renderersList.size()]);
}
 
Example #9
Source File: SimpleExoPlayer.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public void onAudioSessionId(int sessionId) {
  if (audioSessionId == sessionId) {
    return;
  }
  audioSessionId = sessionId;
  for (AudioListener audioListener : audioListeners) {
    // Prevent duplicate notification if a listener is both a AudioRendererEventListener and
    // a AudioListener, as they have the same method signature.
    if (!audioDebugListeners.contains(audioListener)) {
      audioListener.onAudioSessionId(sessionId);
    }
  }
  for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
    audioDebugListener.onAudioSessionId(sessionId);
  }
}
 
Example #10
Source File: DefaultRenderersFactory.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Renderer[] createRenderers(
    Handler eventHandler,
    VideoRendererEventListener videoRendererEventListener,
    AudioRendererEventListener audioRendererEventListener,
    TextOutput textRendererOutput,
    MetadataOutput metadataRendererOutput,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
  if (drmSessionManager == null) {
    drmSessionManager = this.drmSessionManager;
  }
  ArrayList<Renderer> renderersList = new ArrayList<>();
  buildVideoRenderers(context, drmSessionManager, allowedVideoJoiningTimeMs,
      eventHandler, videoRendererEventListener, extensionRendererMode, renderersList);
  buildAudioRenderers(context, drmSessionManager, buildAudioProcessors(),
      eventHandler, audioRendererEventListener, extensionRendererMode, renderersList);
  buildTextRenderers(context, textRendererOutput, eventHandler.getLooper(),
      extensionRendererMode, renderersList);
  buildMetadataRenderers(context, metadataRendererOutput, eventHandler.getLooper(),
      extensionRendererMode, renderersList);
  buildMiscellaneousRenderers(context, eventHandler, extensionRendererMode, renderersList);
  return renderersList.toArray(new Renderer[renderersList.size()]);
}
 
Example #11
Source File: Util.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Extract renderer capabilities for the renderers created by the provided renderers factory.
 *
 * @param renderersFactory A {@link RenderersFactory}.
 * @param drmSessionManager An optional {@link DrmSessionManager} used by the renderers.
 * @return The {@link RendererCapabilities} for each renderer created by the {@code
 *     renderersFactory}.
 */
public static RendererCapabilities[] getRendererCapabilities(
    RenderersFactory renderersFactory,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
  Renderer[] renderers =
      renderersFactory.createRenderers(
          new Handler(),
          new VideoRendererEventListener() {},
          new AudioRendererEventListener() {},
          (cues) -> {},
          (metadata) -> {},
          drmSessionManager);
  RendererCapabilities[] capabilities = new RendererCapabilities[renderers.length];
  for (int i = 0; i < renderers.length; i++) {
    capabilities[i] = renderers[i].getCapabilities();
  }
  return capabilities;
}
 
Example #12
Source File: Util.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Extract renderer capabilities for the renderers created by the provided renderers factory.
 *
 * @param renderersFactory A {@link RenderersFactory}.
 * @param drmSessionManager An optional {@link DrmSessionManager} used by the renderers.
 * @return The {@link RendererCapabilities} for each renderer created by the {@code
 *     renderersFactory}.
 */
public static RendererCapabilities[] getRendererCapabilities(
    RenderersFactory renderersFactory,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
  Renderer[] renderers =
      renderersFactory.createRenderers(
          new Handler(),
          new VideoRendererEventListener() {},
          new AudioRendererEventListener() {},
          (cues) -> {},
          (metadata) -> {},
          drmSessionManager);
  RendererCapabilities[] capabilities = new RendererCapabilities[renderers.length];
  for (int i = 0; i < renderers.length; i++) {
    capabilities[i] = renderers[i].getCapabilities();
  }
  return capabilities;
}
 
Example #13
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link #addAnalyticsListener(AnalyticsListener)} to get more detailed debug
 *     information.
 */
@Deprecated
public void setAudioDebugListener(AudioRendererEventListener listener) {
  audioDebugListeners.retainAll(Collections.singleton(analyticsCollector));
  if (listener != null) {
    addAudioDebugListener(listener);
  }
}
 
Example #14
Source File: SimpleExoPlayer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onAudioDecoderInitialized(String decoderName, long initializedTimestampMs,
    long initializationDurationMs) {
  for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
    audioDebugListener.onAudioDecoderInitialized(decoderName, initializedTimestampMs,
        initializationDurationMs);
  }
}
 
Example #15
Source File: SimpleExoPlayer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onAudioEnabled(DecoderCounters counters) {
  audioDecoderCounters = counters;
  for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
    audioDebugListener.onAudioEnabled(counters);
  }
}
 
Example #16
Source File: SimpleExoPlayer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onAudioSinkUnderrun(int bufferSize, long bufferSizeMs,
    long elapsedSinceLastFeedMs) {
  for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
    audioDebugListener.onAudioSinkUnderrun(bufferSize, bufferSizeMs, elapsedSinceLastFeedMs);
  }
}
 
Example #17
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onAudioDecoderInitialized(String decoderName, long initializedTimestampMs,
    long initializationDurationMs) {
  for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
    audioDebugListener.onAudioDecoderInitialized(decoderName, initializedTimestampMs,
        initializationDurationMs);
  }
}
 
Example #18
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onAudioInputFormatChanged(Format format) {
  audioFormat = format;
  for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
    audioDebugListener.onAudioInputFormatChanged(format);
  }
}
 
Example #19
Source File: FfmpegAudioRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
 *     null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param audioProcessors Optional {@link AudioProcessor}s that will process audio before output.
 */
public FfmpegAudioRenderer(
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    AudioProcessor... audioProcessors) {
  this(
      eventHandler,
      eventListener,
      new DefaultAudioSink(/* audioCapabilities= */ null, audioProcessors),
      /* enableFloatOutput= */ false);
}
 
Example #20
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onAudioSinkUnderrun(int bufferSize, long bufferSizeMs,
    long elapsedSinceLastFeedMs) {
  for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
    audioDebugListener.onAudioSinkUnderrun(bufferSize, bufferSizeMs, elapsedSinceLastFeedMs);
  }
}
 
Example #21
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onAudioDisabled(DecoderCounters counters) {
  for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
    audioDebugListener.onAudioDisabled(counters);
  }
  audioFormat = null;
  audioDecoderCounters = null;
  audioSessionId = C.AUDIO_SESSION_ID_UNSET;
}
 
Example #22
Source File: SimpleExoPlayer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link #addAnalyticsListener(AnalyticsListener)} to get more detailed debug
 *     information.
 */
@Deprecated
@SuppressWarnings("deprecation")
public void setAudioDebugListener(AudioRendererEventListener listener) {
  audioDebugListeners.retainAll(Collections.singleton(analyticsCollector));
  if (listener != null) {
    addAudioDebugListener(listener);
  }
}
 
Example #23
Source File: FfmpegAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
 *     null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param audioProcessors Optional {@link AudioProcessor}s that will process audio before output.
 */
public FfmpegAudioRenderer(
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    AudioProcessor... audioProcessors) {
  this(
      eventHandler,
      eventListener,
      new DefaultAudioSink(/* audioCapabilities= */ null, audioProcessors),
      /* enableFloatOutput= */ false);
}
 
Example #24
Source File: FfmpegAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
 *     null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param audioSink The sink to which audio will be output.
 * @param enableFloatOutput Whether to enable 32-bit float audio format, if supported on the
 *     device/build and if the input format may have bit depth higher than 16-bit. When using
 *     32-bit float output, any audio processing will be disabled, including playback speed/pitch
 *     adjustment.
 */
public FfmpegAudioRenderer(
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    AudioSink audioSink,
    boolean enableFloatOutput) {
  super(
      eventHandler,
      eventListener,
      /* drmSessionManager= */ null,
      /* playClearSamplesWithoutKeys= */ false,
      audioSink);
  this.enableFloatOutput = enableFloatOutput;
}
 
Example #25
Source File: SoftAudioRenderer.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
/**
 * @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
 *     null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param audioProcessors Optional {@link AudioProcessor}s that will process audio before output.
 */
public SoftAudioRenderer(
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    AudioProcessor... audioProcessors) {
  this(
      eventHandler,
      eventListener,
      new DefaultAudioSink(/* audioCapabilities= */ null, audioProcessors),
      /* enableFloatOutput= */ false);
}
 
Example #26
Source File: SoftAudioRenderer.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
/**
 * @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
 *     null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param audioSink The sink to which audio will be output.
 * @param enableFloatOutput Whether to enable 32-bit float audio format, if supported on the
 *     device/build and if the input format may have bit depth higher than 16-bit. When using
 *     32-bit float output, any audio processing will be disabled, including playback speed/pitch
 *     adjustment.
 */
public SoftAudioRenderer(
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    AudioSink audioSink,
    boolean enableFloatOutput) {
  super(
      eventHandler,
      eventListener,
      /* drmSessionManager= */ null,
      /* playClearSamplesWithoutKeys= */ false,
      audioSink);
  this.enableFloatOutput = enableFloatOutput;
}
 
Example #27
Source File: SonicMediaCodecAudioRenderer.java    From K-Sonic with MIT License 5 votes vote down vote up
public SonicMediaCodecAudioRenderer(MediaCodecSelector mediaCodecSelector,
    DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys, Handler eventHandler,
    AudioRendererEventListener eventListener, AudioCapabilities audioCapabilities,
    AudioProcessor... audioProcessors) {
  super(mediaCodecSelector, drmSessionManager, playClearSamplesWithoutKeys, eventHandler, eventListener, audioCapabilities, audioProcessors);
  //Init
  bufferIndex = -1;
  speed = 1.0f;
  pitch = 1.0f;
  rate = 1.0f;
}
 
Example #28
Source File: SimpleExoPlayer.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onAudioSinkUnderrun(int bufferSize, long bufferSizeMs,
    long elapsedSinceLastFeedMs) {
  for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
    audioDebugListener.onAudioSinkUnderrun(bufferSize, bufferSizeMs, elapsedSinceLastFeedMs);
  }
}
 
Example #29
Source File: SimpleExoPlayer.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onAudioEnabled(DecoderCounters counters) {
  audioDecoderCounters = counters;
  for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
    audioDebugListener.onAudioEnabled(counters);
  }
}
 
Example #30
Source File: RendererProvider.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
public RendererProvider(@NonNull Context context, @NonNull Handler handler, @NonNull TextOutput captionListener, @NonNull MetadataOutput metadataListener,
                        @NonNull AudioRendererEventListener audioRendererEventListener, @NonNull VideoRendererEventListener videoRendererEventListener) {
    this.context = context;
    this.handler = handler;
    this.captionListener = captionListener;
    this.metadataListener = metadataListener;
    this.audioRendererEventListener = audioRendererEventListener;
    this.videoRendererEventListener = videoRendererEventListener;
}