public class

FakeAdaptiveMediaSource

extends FakeMediaSource

 java.lang.Object

androidx.media3.exoplayer.source.BaseMediaSource

androidx.media3.test.utils.FakeMediaSource

↳androidx.media3.test.utils.FakeAdaptiveMediaSource

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

Fake MediaSource that provides a given timeline. Creating the period returns a FakeAdaptiveMediaPeriod from the given TrackGroupArray.

Summary

Fields
from FakeMediaSourceFAKE_MEDIA_ITEM
Constructors
publicFakeAdaptiveMediaSource(Timeline timeline, TrackGroupArray trackGroupArray, FakeChunkSource.Factory chunkSourceFactory)

Methods
protected MediaPeriodcreateMediaPeriod(MediaSource.MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, TransferListener transferListener)

Creates a MediaPeriod for this media source.

protected voidreleaseMediaPeriod(MediaPeriod mediaPeriod)

Releases a media period created by FakeMediaSource.

from FakeMediaSourceassertMediaPeriodCreated, assertReleased, canUpdateMediaItem, createPeriod, createWithWindowId, getCreatedMediaPeriods, getInitialTimeline, getLastCreatedActiveMediaPeriod, getMediaItem, getTimeline, isPrepared, isSingleWindow, maybeThrowSourceInfoRefreshError, prepareSourceInternal, releasePeriod, releaseSourceInternal, setAllowPreparation, setCanUpdateMediaItems, setNewSourceInfo, setNewSourceInfo, setPeriodDefersOnPreparedCallback, updateMediaItem
from BaseMediaSourceaddDrmEventListener, addEventListener, createDrmEventDispatcher, createDrmEventDispatcher, createEventDispatcher, createEventDispatcher, createEventDispatcher, createEventDispatcher, disable, disableInternal, enable, enableInternal, getPlayerId, isEnabled, prepareSource, prepareSource, prepareSourceCalled, refreshSourceInfo, releaseSource, removeDrmEventListener, removeEventListener, setPlayerId
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public FakeAdaptiveMediaSource(Timeline timeline, TrackGroupArray trackGroupArray, FakeChunkSource.Factory chunkSourceFactory)

Methods

protected MediaPeriod createMediaPeriod(MediaSource.MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, TransferListener transferListener)

Creates a MediaPeriod for this media source.

Parameters:

id: The identifier of the period.
trackGroupArray: The TrackGroupArray supported by the media period.
allocator: An Allocator from which to obtain media buffer allocations.
mediaSourceEventDispatcher: An to dispatch media source events.
drmSessionManager: A DrmSessionManager to allow DRM interactions.
drmEventDispatcher: An to dispatch DRM events.
transferListener: The transfer listener which should be informed of any data transfers. May be null if no listener is available.

Returns:

A new MediaPeriod.

protected void releaseMediaPeriod(MediaPeriod mediaPeriod)

Releases a media period created by FakeMediaSource.

Source

/*
 * Copyright (C) 2017 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 androidx.annotation.Nullable;
import androidx.media3.common.Timeline;
import androidx.media3.common.Timeline.Period;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import androidx.media3.datasource.TransferListener;
import androidx.media3.exoplayer.drm.DrmSessionEventListener;
import androidx.media3.exoplayer.drm.DrmSessionManager;
import androidx.media3.exoplayer.source.MediaPeriod;
import androidx.media3.exoplayer.source.MediaSource;
import androidx.media3.exoplayer.source.MediaSourceEventListener;
import androidx.media3.exoplayer.source.TrackGroupArray;
import androidx.media3.exoplayer.upstream.Allocator;

/**
 * Fake {@link MediaSource} that provides a given timeline. Creating the period returns a {@link
 * FakeAdaptiveMediaPeriod} from the given {@link TrackGroupArray}.
 */
@UnstableApi
public class FakeAdaptiveMediaSource extends FakeMediaSource {

  private final FakeChunkSource.Factory chunkSourceFactory;

  public FakeAdaptiveMediaSource(
      Timeline timeline,
      TrackGroupArray trackGroupArray,
      FakeChunkSource.Factory chunkSourceFactory) {
    super(
        timeline,
        DrmSessionManager.DRM_UNSUPPORTED,
        /* trackDataFactory= */ (unusedFormat, unusedMediaPeriodId) -> {
          throw new RuntimeException("Unused TrackDataFactory");
        },
        trackGroupArray);
    this.chunkSourceFactory = chunkSourceFactory;
  }

  @Override
  protected MediaPeriod createMediaPeriod(
      MediaPeriodId id,
      TrackGroupArray trackGroupArray,
      Allocator allocator,
      MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher,
      DrmSessionManager drmSessionManager,
      DrmSessionEventListener.EventDispatcher drmEventDispatcher,
      @Nullable TransferListener transferListener) {
    Period period = Util.castNonNull(getTimeline()).getPeriodByUid(id.periodUid, new Period());
    return new FakeAdaptiveMediaPeriod(
        trackGroupArray,
        mediaSourceEventDispatcher,
        allocator,
        chunkSourceFactory,
        period.durationUs,
        transferListener);
  }

  @Override
  public void releaseMediaPeriod(MediaPeriod mediaPeriod) {
    ((FakeAdaptiveMediaPeriod) mediaPeriod).release();
  }
}