# BaseMediaChunkIterator

Artifact: [androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/source/chunk/BaseMediaChunkIterator.java+class:androidx.media3.exoplayer.source.chunk.BaseMediaChunkIterator)

*** ** * ** ***


```
@UnstableApi
public abstract class BaseMediaChunkIterator implements MediaChunkIterator
```

<br />

Known direct subclasses [DefaultDashChunkSource.RepresentationSegmentIterator](https://developer.android.com/reference/androidx/media3/exoplayer/dash/DefaultDashChunkSource.RepresentationSegmentIterator), [FakeAdaptiveDataSet.Iterator](https://developer.android.com/reference/androidx/media3/test/utils/FakeAdaptiveDataSet.Iterator), [FakeMediaChunkIterator](https://developer.android.com/reference/androidx/media3/test/utils/FakeMediaChunkIterator)

|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DefaultDashChunkSource.RepresentationSegmentIterator` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunkIterator` wrapping a `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DefaultDashChunkSource.RepresentationHolder`. |
| `https://developer.android.com/reference/androidx/media3/test/utils/FakeAdaptiveDataSet.Iterator` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunkIterator` for the chunks defined by a fake adaptive data set. |
| `https://developer.android.com/reference/androidx/media3/test/utils/FakeMediaChunkIterator` | Fake `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunkIterator`. |

*** ** * ** ***

Base class for `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunkIterator`s. Handles `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/BaseMediaChunkIterator#next()` and `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/BaseMediaChunkIterator#isEnded()`, and provides a bounds check for child classes.

## Summary

| ### Protected fields |
|---|---|
| `long` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/BaseMediaChunkIterator#currentIndex()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/BaseMediaChunkIterator#BaseMediaChunkIterator(long,long)(long fromIndex, long toIndex)` Creates base iterator. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/BaseMediaChunkIterator#isEnded()()` Returns whether the iteration has reached the end of the available data. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/BaseMediaChunkIterator#next()()` Moves the iterator to the next media chunk. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/BaseMediaChunkIterator#reset()()` Resets the iterator to the initial position. |

| ### Protected methods |
|---|---|
| `final void` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/BaseMediaChunkIterator#checkInBounds()()` Verifies that the iterator points to a valid element. |
| `final long` | `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/BaseMediaChunkIterator#getCurrentIndex()()` Returns the current index this iterator is pointing to. |

### Inherited Constants

From [androidx.media3.exoplayer.source.chunk.MediaChunkIterator](https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunkIterator) `static final https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunkIterator` `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunkIterator#EMPTY()`

An empty media chunk iterator without available data.

### Inherited methods

From [androidx.media3.exoplayer.source.chunk.MediaChunkIterator](https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunkIterator) `abstract long` `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunkIterator#getChunkEndTimeUs()()`

Returns the media end time of the chunk, in microseconds.
`abstract long` `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunkIterator#getChunkStartTimeUs()()`

Returns the media start time of the chunk, in microseconds.
`abstract https://developer.android.com/reference/androidx/media3/datasource/DataSpec` `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunkIterator#getDataSpec()()`

Returns the `https://developer.android.com/reference/androidx/media3/datasource/DataSpec` used to load the media chunk.
`int` `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunkIterator#getLocationSteeringPriorityIndex()()`

Returns the index in the steering priority list of the locations (e.g., DASH service location or HLS pathway) for the current media chunks, or `Integer.MAX_VALUE` if steering is inactive or unavailable.

## Protected fields

### currentIndex

```
protected long currentIndex
```

## Public constructors

### BaseMediaChunkIterator

```
public BaseMediaChunkIterator(long fromIndex, long toIndex)
```

Creates base iterator.

| Parameters |
|---|---|
| `long fromIndex` | The first available index. |
| `long toIndex` | The last available index. |

## Public methods

### isEnded

```
public boolean isEnded()
```

Returns whether the iteration has reached the end of the available data.

### next

```
public boolean next()
```

Moves the iterator to the next media chunk.

Check the return value or `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunkIterator#isEnded()` to determine whether the iterator reached the end of the available data.

| Returns |
|---|---|
| `boolean` | Whether the iterator points to a media chunk with available data. |

### reset

```
public void reset()
```

Resets the iterator to the initial position.

## Protected methods

### checkInBounds

```
protected final void checkInBounds()
```

Verifies that the iterator points to a valid element.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/util/NoSuchElementException.html` | If the iterator does not point to a valid element. |

### getCurrentIndex

```
protected final long getCurrentIndex()
```

Returns the current index this iterator is pointing to.