public abstract class

BaseMediaChunkIterator

extends java.lang.Object

implements MediaChunkIterator

 java.lang.Object

↳androidx.media3.exoplayer.source.chunk.BaseMediaChunkIterator

Subclasses:

DefaultDashChunkSource.RepresentationSegmentIterator, FakeMediaChunkIterator, FakeAdaptiveDataSet.Iterator

Gradle dependencies

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

  • groupId: androidx.media3
  • artifactId: media3-exoplayer
  • version: 1.5.0-alpha01

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

Overview

Base class for MediaChunkIterators. Handles BaseMediaChunkIterator.next() and BaseMediaChunkIterator.isEnded(), and provides a bounds check for child classes.

Summary

Constructors
publicBaseMediaChunkIterator(long fromIndex, long toIndex)

Creates base iterator.

Methods
protected final voidcheckInBounds()

Verifies that the iterator points to a valid element.

protected final longgetCurrentIndex()

Returns the current index this iterator is pointing to.

public booleanisEnded()

public booleannext()

public voidreset()

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public BaseMediaChunkIterator(long fromIndex, long toIndex)

Creates base iterator.

Parameters:

fromIndex: The first available index.
toIndex: The last available index.

Methods

public boolean isEnded()

public boolean next()

public void reset()

protected final void checkInBounds()

Verifies that the iterator points to a valid element.

protected final long getCurrentIndex()

Returns the current index this iterator is pointing to.

Source

/*
 * Copyright (C) 2018 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.exoplayer.source.chunk;

import androidx.media3.common.util.UnstableApi;
import java.util.NoSuchElementException;

/**
 * Base class for {@link MediaChunkIterator}s. Handles {@link #next()} and {@link #isEnded()}, and
 * provides a bounds check for child classes.
 */
@UnstableApi
public abstract class BaseMediaChunkIterator implements MediaChunkIterator {

  private final long fromIndex;
  private final long toIndex;

  private long currentIndex;

  /**
   * Creates base iterator.
   *
   * @param fromIndex The first available index.
   * @param toIndex The last available index.
   */
  @SuppressWarnings("nullness:method.invocation")
  public BaseMediaChunkIterator(long fromIndex, long toIndex) {
    this.fromIndex = fromIndex;
    this.toIndex = toIndex;
    reset();
  }

  @Override
  public boolean isEnded() {
    return currentIndex > toIndex;
  }

  @Override
  public boolean next() {
    currentIndex++;
    return !isEnded();
  }

  @Override
  public void reset() {
    currentIndex = fromIndex - 1;
  }

  /**
   * Verifies that the iterator points to a valid element.
   *
   * @throws NoSuchElementException If the iterator does not point to a valid element.
   */
  protected final void checkInBounds() {
    if (currentIndex < fromIndex || currentIndex > toIndex) {
      throw new NoSuchElementException();
    }
  }

  /** Returns the current index this iterator is pointing to. */
  protected final long getCurrentIndex() {
    return currentIndex;
  }
}