# DashWrappingSegmentIndex

# DashWrappingSegmentIndex

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/DashWrappingSegmentIndex.java+class:androidx.media3.exoplayer.dash.DashWrappingSegmentIndex)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/exoplayer/dash/DashWrappingSegmentIndex "View this page in Java")

<br />

```
@UnstableApi
class DashWrappingSegmentIndex : DashSegmentIndex
```

<br />

*** ** * ** ***

An implementation of[DashSegmentIndex](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashSegmentIndex)that wraps a[ChunkIndex](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex)parsed from a media stream.

## Summary

|                                                                                                                                                                                                  ### Public constructors                                                                                                                                                                                                  |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [DashWrappingSegmentIndex](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashWrappingSegmentIndex#DashWrappingSegmentIndex(androidx.media3.extractor.ChunkIndex,long))`(chunkIndex: `[ChunkIndex](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex)`!, timeOffsetUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` |

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

|                                                                                                                                                                                                                                                                                                     ### Inherited Constants                                                                                                                                                                                                                                                                                                     |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From[androidx.media3.exoplayer.dash.DashSegmentIndex](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashSegmentIndex) |-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------| | `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [INDEX_UNBOUNDED](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashSegmentIndex#INDEX_UNBOUNDED())` = -1` | |

## Public constructors

### DashWrappingSegmentIndex

```
DashWrappingSegmentIndex(chunkIndex: ChunkIndex!, timeOffsetUs: Long)
```  

|                                                     Parameters                                                     |
|--------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| `chunkIndex: `[ChunkIndex](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex)`!` | The[ChunkIndex](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ChunkIndex)to wrap. |
| `timeOffsetUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                      | An offset to subtract from the times in the wrapped index, in microseconds.                                  |

## Public functions

### getAvailableSegmentCount

```
fun getAvailableSegmentCount(periodDurationUs: Long, nowUnixTimeUs: Long): Long
```

Returns the number of available segments in the index.  

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

|                                    Returns                                    |
|-------------------------------------------------------------------------------|------------------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The number of available segments in the index. |

### getDurationUs

```
fun getDurationUs(segmentNum: Long, periodDurationUs: Long): Long
```

Returns the duration of a segment.  

|                                            Parameters                                             |
|---------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `segmentNum: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)       | The segment number.                                                                                                                                                                                  |
| `periodDurationUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The duration of the enclosing period in microseconds, or[TIME_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#TIME_UNSET())if the period's duration is not yet known. |

|                                    Returns                                    |
|-------------------------------------------------------------------------------|-----------------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The duration of the segment, in microseconds. |

### getFirstAvailableSegmentNum

```
fun getFirstAvailableSegmentNum(periodDurationUs: Long, nowUnixTimeUs: Long): Long
```

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

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

|                                    Returns                                    |
|-------------------------------------------------------------------------------|--------------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The number of the first available segment. |

### getFirstSegmentNum

```
fun getFirstSegmentNum(): Long
```

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

### getNextSegmentAvailableTimeUs

```
fun getNextSegmentAvailableTimeUs(
    periodDurationUs: Long,
    nowUnixTimeUs: Long
): Long
```

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

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

|                                    Returns                                    |
|-------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The time, in microseconds, at which a new segment becomes available, or[TIME_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#TIME_UNSET())if not applicable. |

### getSegmentCount

```
fun getSegmentCount(periodDurationUs: Long): Long
```

Returns the number of segments defined in the index, or[INDEX_UNBOUNDED](https://developer.android.com/reference/kotlin/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[getFirstAvailableSegmentNum](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashSegmentIndex#getFirstAvailableSegmentNum(long,long))and[getAvailableSegmentCount](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashSegmentIndex#getAvailableSegmentCount(long,long)).  

|                                            Parameters                                             |
|---------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `periodDurationUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The duration of the enclosing period in microseconds, or[TIME_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#TIME_UNSET())if the period's duration is not yet known. |

|                                    Returns                                    |
|-------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The number of segments in the index, or[INDEX_UNBOUNDED](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/DashSegmentIndex#INDEX_UNBOUNDED()). |

### getSegmentNum

```
fun getSegmentNum(timeUs: Long, periodDurationUs: Long): Long
```

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                                             |
|---------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `timeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)           | The time in microseconds.                                                                                                                                                                            |
| `periodDurationUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The duration of the enclosing period in microseconds, or[TIME_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#TIME_UNSET())if the period's duration is not yet known. |

|                                    Returns                                    |
|-------------------------------------------------------------------------------|--------------------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The segment number of the corresponding segment. |

### getSegmentUrl

```
fun getSegmentUrl(segmentNum: Long): RangedUri!
```

Returns a[RangedUri](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/manifest/RangedUri)defining the location of a segment.  

|                                         Parameters                                          |
|---------------------------------------------------------------------------------------------|---------------------|
| `segmentNum: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The segment number. |

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

### getTimeUs

```
fun getTimeUs(segmentNum: Long): Long
```

Returns the start time of a segment.  

|                                         Parameters                                          |
|---------------------------------------------------------------------------------------------|---------------------|
| `segmentNum: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The segment number. |

|                                    Returns                                    |
|-------------------------------------------------------------------------------|-----------------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The corresponding start time in microseconds. |

### isExplicit

```
fun isExplicit(): Boolean
```

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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether segments are defined explicitly by the index. |