# DashSegmentIndex

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

*** ** * ** ***


```
@UnstableApi
public interface DashSegmentIndex
```

<br />

Known direct subclasses [DashWrappingSegmentIndex](https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashWrappingSegmentIndex), [Representation.MultiSegmentRepresentation](https://developer.android.com/reference/androidx/media3/exoplayer/dash/manifest/Representation.MultiSegmentRepresentation)

|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashWrappingSegmentIndex` | An implementation of `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex` that wraps a `https://developer.android.com/reference/androidx/media3/extractor/ChunkIndex` parsed from a media stream. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/dash/manifest/Representation.MultiSegmentRepresentation` | A DASH representation consisting of multiple segments. |

*** ** * ** ***

Indexes the segments within a media stream.

## Summary

| ### Constants |
|---|---|
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#INDEX_UNBOUNDED() = -1` |

| ### Public methods |
|---|---|
| `abstract long` | `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#getAvailableSegmentCount(long,long)(long periodDurationUs, long nowUnixTimeUs)` Returns the number of available segments in the index. |
| `abstract long` | `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#getDurationUs(long,long)(long segmentNum, long periodDurationUs)` Returns the duration of a segment. |
| `abstract long` | `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#getFirstAvailableSegmentNum(long,long)(long periodDurationUs, long nowUnixTimeUs)` Returns the segment number of the first available segment in the index. |
| `abstract long` | `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#getFirstSegmentNum()()` Returns the segment number of the first defined segment in the index. |
| `abstract long` | `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#getNextSegmentAvailableTimeUs(long,long)( long periodDurationUs, long nowUnixTimeUs )` Returns the time, in microseconds, at which a new segment becomes available, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if not applicable. |
| `abstract long` | `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#getSegmentCount(long)(long periodDurationUs)` Returns the number of segments defined in the index, or `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#INDEX_UNBOUNDED()`. |
| `abstract long` | `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#getSegmentNum(long,long)(long timeUs, long periodDurationUs)` Returns `getFirstSegmentNum()` if the index has no segments or if the given media time is earlier than the start of the first segment. |
| `abstract https://developer.android.com/reference/androidx/media3/exoplayer/dash/manifest/RangedUri` | `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#getSegmentUrl(long)(long segmentNum)` Returns a `https://developer.android.com/reference/androidx/media3/exoplayer/dash/manifest/RangedUri` defining the location of a segment. |
| `abstract long` | `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#getTimeUs(long)(long segmentNum)` Returns the start time of a segment. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#isExplicit()()` Returns true if segments are defined explicitly by the index. |

## Constants

### INDEX_UNBOUNDED

```
default static final int INDEX_UNBOUNDED = -1
```

## Public methods

### getAvailableSegmentCount

```
abstract long getAvailableSegmentCount(long periodDurationUs, long nowUnixTimeUs)
```

Returns the number of available segments in the index.

| Parameters |
|---|---|
| `long periodDurationUs` | The duration of the enclosing period in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if the period's duration is not yet known. |
| `long nowUnixTimeUs` | The current time in milliseconds since the Unix epoch. |

| Returns |
|---|---|
| `long` | The number of available segments in the index. |

### getDurationUs

```
abstract long getDurationUs(long segmentNum, long periodDurationUs)
```

Returns the duration of a segment.

| Parameters |
|---|---|
| `long segmentNum` | The segment number. |
| `long periodDurationUs` | The duration of the enclosing period in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if the period's duration is not yet known. |

| Returns |
|---|---|
| `long` | The duration of the segment, in microseconds. |

### getFirstAvailableSegmentNum

```
abstract long getFirstAvailableSegmentNum(long periodDurationUs, long nowUnixTimeUs)
```

Returns the segment number of the first available segment in the index.

| Parameters |
|---|---|
| `long periodDurationUs` | The duration of the enclosing period in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if the period's duration is not yet known. |
| `long nowUnixTimeUs` | The current time in milliseconds since the Unix epoch. |

| Returns |
|---|---|
| `long` | The number of the first available segment. |

### getFirstSegmentNum

```
abstract long getFirstSegmentNum()
```

Returns the segment number of the first defined segment in the index.

### getNextSegmentAvailableTimeUs

```
abstract long getNextSegmentAvailableTimeUs(
    long periodDurationUs,
    long nowUnixTimeUs
)
```

Returns the time, in microseconds, at which a new segment becomes available, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if not applicable.

| Parameters |
|---|---|
| `long periodDurationUs` | The duration of the enclosing period in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if the period's duration is not yet known. |
| `long nowUnixTimeUs` | The current time in milliseconds since the Unix epoch. |

| Returns |
|---|---|
| `long` | The time, in microseconds, at which a new segment becomes available, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if not applicable. |

### getSegmentCount

```
abstract long getSegmentCount(long periodDurationUs)
```

Returns the number of segments defined in the index, or `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#INDEX_UNBOUNDED()`.

An unbounded index occurs if a dynamic manifest uses SegmentTemplate elements without a SegmentTimeline element, and if the period duration is not yet known. In this case the caller can query the available segment using `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#getFirstAvailableSegmentNum(long,long)` and `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#getAvailableSegmentCount(long,long)`.

| Parameters |
|---|---|
| `long periodDurationUs` | The duration of the enclosing period in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if the period's duration is not yet known. |

| Returns |
|---|---|
| `long` | The number of segments in the index, or `https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashSegmentIndex#INDEX_UNBOUNDED()`. |

### getSegmentNum

```
abstract long getSegmentNum(long timeUs, long periodDurationUs)
```

Returns `getFirstSegmentNum()` if the index has no segments or if the given media time is earlier than the start of the first segment. Returns `getFirstSegmentNum() +
getSegmentCount() - 1` if the given media time is later than the end of the last segment. Otherwise, returns the segment number of the segment containing the given media time.

| Parameters |
|---|---|
| `long timeUs` | The time in microseconds. |
| `long periodDurationUs` | The duration of the enclosing period in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if the period's duration is not yet known. |

| Returns |
|---|---|
| `long` | The segment number of the corresponding segment. |

### getSegmentUrl

```
abstract RangedUri getSegmentUrl(long segmentNum)
```

Returns a `https://developer.android.com/reference/androidx/media3/exoplayer/dash/manifest/RangedUri` defining the location of a segment.

| Parameters |
|---|---|
| `long segmentNum` | The segment number. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/dash/manifest/RangedUri` | The `https://developer.android.com/reference/androidx/media3/exoplayer/dash/manifest/RangedUri` defining the location of the data. |

### getTimeUs

```
abstract long getTimeUs(long segmentNum)
```

Returns the start time of a segment.

| Parameters |
|---|---|
| `long segmentNum` | The segment number. |

| Returns |
|---|---|
| `long` | The corresponding start time in microseconds. |

### isExplicit

```
abstract boolean isExplicit()
```

Returns true if segments are defined explicitly by the index.

If true is returned, each segment is defined explicitly by the index data, and all of the listed segments are guaranteed to be available at the time when the index was obtained.

If false is returned then segment information was derived from properties such as a fixed segment duration. If the presentation is dynamic, it's possible that only a subset of the segments are available.

| Returns |
|---|---|
| `boolean` | Whether segments are defined explicitly by the index. |