public class

FakeAudioRenderer

extends FakeRenderer

 java.lang.Object

androidx.media3.exoplayer.BaseRenderer

androidx.media3.test.utils.FakeRenderer

↳androidx.media3.test.utils.FakeAudioRenderer

Gradle dependencies

compile group: 'androidx.media3', name: 'media3-test-utils', version: '1.5.0-alpha01'

  • groupId: androidx.media3
  • artifactId: media3-test-utils
  • version: 1.5.0-alpha01

Artifact androidx.media3:media3-test-utils:1.5.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

A FakeRenderer that supports C.TRACK_TYPE_AUDIO.

Summary

Fields
from FakeRendererenabledCount, isEnded, isInitialized, isReleased, positionResetCount, resetCount, sampleBufferReadCount
Constructors
publicFakeAudioRenderer(HandlerWrapper handler, AudioRendererEventListener eventListener)

Methods
protected voidonDisabled()

Called when the renderer is disabled.

protected voidonEnabled(boolean joining, boolean mayRenderStartOfStream)

Called when the renderer is enabled.

protected voidonFormatChanged(Format format)

Called when the renderer reads a new format.

protected booleanshouldProcessBuffer(long bufferTimeUs, long playbackPositionUs)

Called before the renderer processes a buffer.

from FakeRenderergetFormatsRead, getName, isEnded, isReady, onInit, onPositionReset, onRelease, onReset, render, supportsFormat
from BaseRendererclearListener, createRendererException, createRendererException, disable, enable, getCapabilities, getClock, getConfiguration, getFormatHolder, getIndex, getLastResetPositionUs, getMediaClock, getPlayerId, getReadingPositionUs, getState, getStream, getStreamFormats, getStreamOffsetUs, getTimeline, getTrackType, handleMessage, hasReadStreamToEnd, init, isCurrentStreamFinal, isSourceReady, maybeThrowStreamError, onRendererCapabilitiesChanged, onStarted, onStopped, onStreamChanged, onTimelineChanged, readSource, release, replaceStream, reset, resetPosition, setCurrentStreamFinal, setListener, setTimeline, skipSource, start, stop, supportsMixedMimeTypeAdaptation
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public FakeAudioRenderer(HandlerWrapper handler, AudioRendererEventListener eventListener)

Methods

protected void onEnabled(boolean joining, boolean mayRenderStartOfStream)

Called when the renderer is enabled.

The default implementation is a no-op.

Parameters:

joining: Whether this renderer is being enabled to join an ongoing playback.
mayRenderStartOfStream: Whether this renderer is allowed to render the start of the stream even if the state is not Renderer.STATE_STARTED yet.

protected void onDisabled()

Called when the renderer is disabled.

The default implementation is a no-op.

protected void onFormatChanged(Format format)

Called when the renderer reads a new format.

protected boolean shouldProcessBuffer(long bufferTimeUs, long playbackPositionUs)

Called before the renderer processes a buffer.

Parameters:

bufferTimeUs: The buffer timestamp, in microseconds.
playbackPositionUs: The playback position, in microseconds

Returns:

Whether the buffer should be processed.

Source

/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.media3.test.utils;

import android.os.SystemClock;
import androidx.media3.common.C;
import androidx.media3.common.Format;
import androidx.media3.common.util.HandlerWrapper;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.exoplayer.DecoderCounters;
import androidx.media3.exoplayer.ExoPlaybackException;
import androidx.media3.exoplayer.audio.AudioRendererEventListener;

/** A {@link FakeRenderer} that supports {@link C#TRACK_TYPE_AUDIO}. */
@UnstableApi
public class FakeAudioRenderer extends FakeRenderer {

  private final HandlerWrapper handler;
  private final AudioRendererEventListener eventListener;
  private final DecoderCounters decoderCounters;
  private boolean notifiedPositionAdvancing;

  public FakeAudioRenderer(HandlerWrapper handler, AudioRendererEventListener eventListener) {
    super(C.TRACK_TYPE_AUDIO);
    this.handler = handler;
    this.eventListener = eventListener;
    decoderCounters = new DecoderCounters();
  }

  @Override
  protected void onEnabled(boolean joining, boolean mayRenderStartOfStream)
      throws ExoPlaybackException {
    super.onEnabled(joining, mayRenderStartOfStream);
    handler.post(() -> eventListener.onAudioEnabled(decoderCounters));
    notifiedPositionAdvancing = false;
  }

  @Override
  protected void onDisabled() {
    super.onDisabled();
    handler.post(() -> eventListener.onAudioDisabled(decoderCounters));
  }

  @Override
  protected void onFormatChanged(Format format) {
    handler.post(
        () -> eventListener.onAudioInputFormatChanged(format, /* decoderReuseEvaluation= */ null));
    handler.post(
        () ->
            eventListener.onAudioDecoderInitialized(
                /* decoderName= */ "fake.audio.decoder",
                /* initializedTimestampMs= */ SystemClock.elapsedRealtime(),
                /* initializationDurationMs= */ 0));
  }

  @Override
  protected boolean shouldProcessBuffer(long bufferTimeUs, long playbackPositionUs) {
    boolean shouldProcess = super.shouldProcessBuffer(bufferTimeUs, playbackPositionUs);
    if (shouldProcess && !notifiedPositionAdvancing) {
      handler.post(() -> eventListener.onAudioPositionAdvancing(System.currentTimeMillis()));
      notifiedPositionAdvancing = true;
    }
    return shouldProcess;
  }
}