# PlayerEmsgHandler.PlayerTrackEmsgHandler

# PlayerEmsgHandler.PlayerTrackEmsgHandler

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

*** ** * ** ***

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

<br />

```
inner class PlayerEmsgHandler.PlayerTrackEmsgHandler : TrackOutput
```

<br />

*** ** * ** ***

Handles emsg messages for a specific track for the player.

## Summary

|                                ### Public functions                                 |
|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [format](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/PlayerEmsgHandler.PlayerTrackEmsgHandler#format(androidx.media3.common.Format))`(format: `[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!)` Called when the[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)of the track has been extracted from the stream.                                                                                                                                                                                                                                                                                                                                                                                                      |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [maybeRefreshManifestBeforeLoadingNextChunk](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/PlayerEmsgHandler.PlayerTrackEmsgHandler#maybeRefreshManifestBeforeLoadingNextChunk(long))`(` ` presentationPositionUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) `)` For live streaming, check if the DASH manifest is expired before the next segment start time.                                                                                                                                                                                                                                                                                                                                                                                                    |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [onChunkLoadCompleted](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/PlayerEmsgHandler.PlayerTrackEmsgHandler#onChunkLoadCompleted(androidx.media3.exoplayer.source.chunk.Chunk))`(chunk: `[Chunk](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk)`!)` Called when a chunk load has been completed.                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [onChunkLoadError](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/PlayerEmsgHandler.PlayerTrackEmsgHandler#onChunkLoadError(androidx.media3.exoplayer.source.chunk.Chunk))`(chunk: `[Chunk](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk)`!)` Called when a chunk load has encountered an error.                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [release](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/PlayerEmsgHandler.PlayerTrackEmsgHandler#release())`()` Release this track emsg handler.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [sampleData](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/PlayerEmsgHandler.PlayerTrackEmsgHandler#sampleData(androidx.media3.common.util.ParsableByteArray,int,int))`(` ` data: `[ParsableByteArray](https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray)`!,` ` length: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` @`[TrackOutput.SampleDataPart](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput.SampleDataPart)` sampleDataPart: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` Called to write sample data to the output.                                                                                                                  |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)         | [sampleData](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/PlayerEmsgHandler.PlayerTrackEmsgHandler#sampleData(androidx.media3.common.DataReader,int,boolean,int))`(` ` input: `[DataReader](https://developer.android.com/reference/kotlin/androidx/media3/common/DataReader)`!,` ` length: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` allowEndOfInput: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`,` ` @`[TrackOutput.SampleDataPart](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput.SampleDataPart)` sampleDataPart: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` Called to write sample data to the output.                             |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [sampleMetadata](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/dash/PlayerEmsgHandler.PlayerTrackEmsgHandler#sampleMetadata(long,int,int,int,androidx.media3.extractor.TrackOutput.CryptoData))`(` ` timeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` flags: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` size: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` offset: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` cryptoData: `[TrackOutput.CryptoData](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput.CryptoData)`?` `)` Called when metadata associated with a sample has been extracted from the stream. |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ### Inherited Constants                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From[androidx.media3.extractor.TrackOutput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput) |-------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [SAMPLE_DATA_PART_ENCRYPTION](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput#SAMPLE_DATA_PART_ENCRYPTION())` = 1` Sample encryption data.       | | `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [SAMPLE_DATA_PART_MAIN](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput#SAMPLE_DATA_PART_MAIN())` = 0` Main media sample data.                   | | `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [SAMPLE_DATA_PART_SUPPLEMENTAL](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput#SAMPLE_DATA_PART_SUPPLEMENTAL())` = 2` Sample supplemental data. | |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ### Inherited functions                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From[androidx.media3.extractor.TrackOutput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput) |-------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [durationUs](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput#durationUs(long))`(durationUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Called to set the duration of the track in microseconds.                                                                                                                                                                                                                                                                                                                                                                                                                                   | | [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [sampleData](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.util.ParsableByteArray,int))`(data: `[ParsableByteArray](https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray)`!, length: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Equivalent to[sampleData](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.util.ParsableByteArray,int,int))sampleData(data, length, SAMPLE_DATA_PART_MAIN)}.                                                                                      | | [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)   | [sampleData](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.DataReader,int,boolean))`(input: `[DataReader](https://developer.android.com/reference/kotlin/androidx/media3/common/DataReader)`!, length: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, allowEndOfInput: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Equivalent to[sampleData(input, length, allowEndOfInput, SAMPLE_DATA_PART_MAIN)](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.DataReader,int,boolean,int)). | |

## Public functions

### format

```
fun format(format: Format!): Unit
```

Called when the[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)of the track has been extracted from the stream.  

|                                             Parameters                                              |
|-----------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|
| `format: `[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!` | The extracted[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format). |

### maybeRefreshManifestBeforeLoadingNextChunk

```
fun maybeRefreshManifestBeforeLoadingNextChunk(
    presentationPositionUs: Long
): Boolean
```

For live streaming, check if the DASH manifest is expired before the next segment start time. If it is, the DASH media source will be notified to refresh the manifest.  

|                                               Parameters                                                |
|---------------------------------------------------------------------------------------------------------|----------------------------------------------|
| `presentationPositionUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The next load position in presentation time. |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|---------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | True if manifest refresh has been requested, false otherwise. |

### onChunkLoadCompleted

```
fun onChunkLoadCompleted(chunk: Chunk!): Unit
```

Called when a chunk load has been completed.  

|                                                    Parameters                                                    |
|------------------------------------------------------------------------------------------------------------------|------------------------------------------|
| `chunk: `[Chunk](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk)`!` | The chunk whose load has been completed. |

### onChunkLoadError

```
fun onChunkLoadError(chunk: Chunk!): Boolean
```

Called when a chunk load has encountered an error.  

|                                                    Parameters                                                    |
|------------------------------------------------------------------------------------------------------------------|--------------------------------------------|
| `chunk: `[Chunk](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/chunk/Chunk)`!` | The chunk whose load encountered an error. |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether a manifest refresh has been requested. |

### release

```
fun release(): Unit
```

Release this track emsg handler. It should not be reused after this call.  

### sampleData

```
fun sampleData(
    data: ParsableByteArray!,
    length: Int,
    @TrackOutput.SampleDataPart sampleDataPart: Int
): Unit
```

Called to write sample data to the output.  

|                                                                                                             Parameters                                                                                                             |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `data: `[ParsableByteArray](https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray)`!`                                                                                                       | A[ParsableByteArray](https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray)from which to read the sample data. |
| `length: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                              | The number of bytes to read, starting from`data.getPosition()`.                                                                                       |
| `@`[TrackOutput.SampleDataPart](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput.SampleDataPart)` sampleDataPart: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The part of the sample data to which this call corresponds.                                                                                           |

### sampleData

```
fun sampleData(
    input: DataReader!,
    length: Int,
    allowEndOfInput: Boolean,
    @TrackOutput.SampleDataPart sampleDataPart: Int
): Int
```

Called to write sample data to the output.  

|                                                                                                             Parameters                                                                                                             |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `input: `[DataReader](https://developer.android.com/reference/kotlin/androidx/media3/common/DataReader)`!`                                                                                                                         | A[DataReader](https://developer.android.com/reference/kotlin/androidx/media3/common/DataReader)from which to read the sample data.                                                                                                                                                                                                                                                    |
| `length: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                              | The maximum length to read from the input.                                                                                                                                                                                                                                                                                                                                            |
| `allowEndOfInput: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                                             | True if encountering the end of the input having read no data is allowed, and should result in[RESULT_END_OF_INPUT](https://developer.android.com/reference/kotlin/androidx/media3/common/C#RESULT_END_OF_INPUT())being returned. False if it should be considered an error, causing an[EOFException](https://developer.android.com/reference/java/io/EOFException.html)to be thrown. |
| `@`[TrackOutput.SampleDataPart](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput.SampleDataPart)` sampleDataPart: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The part of the sample data to which this call corresponds.                                                                                                                                                                                                                                                                                                                           |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|-------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The number of bytes appended. |

|                                         Throws                                          |
|-----------------------------------------------------------------------------------------|----------------------------------------------|
| [java.io.IOException](https://developer.android.com/reference/java/io/IOException.html) | If an error occurred reading from the input. |

### sampleMetadata

```
fun sampleMetadata(
    timeUs: Long,
    flags: Int,
    size: Int,
    offset: Int,
    cryptoData: TrackOutput.CryptoData?
): Unit
```

Called when metadata associated with a sample has been extracted from the stream.

The corresponding sample data will have already been passed to the output via calls to[sampleData](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.DataReader,int,boolean))or[sampleData](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.util.ParsableByteArray,int)).  

|                                                                 Parameters                                                                 |
|--------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `timeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                    | The media timestamp associated with the sample, in microseconds.                                                                                                                                                                                                                                                                                                                                                                                      |
| `flags: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                       | Flags associated with the sample. See`C.BUFFER_FLAG_*`.                                                                                                                                                                                                                                                                                                                                                                                               |
| `size: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                        | The size of the sample data, in bytes.                                                                                                                                                                                                                                                                                                                                                                                                                |
| `offset: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                      | The number of bytes that have been passed to[sampleData](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.DataReader,int,boolean))or[sampleData](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.util.ParsableByteArray,int))since the last byte belonging to the sample whose metadata is being passed. |
| `cryptoData: `[TrackOutput.CryptoData](https://developer.android.com/reference/kotlin/androidx/media3/extractor/TrackOutput.CryptoData)`?` | The encryption data required to decrypt the sample. May be null.                                                                                                                                                                                                                                                                                                                                                                                      |