# AudioTrack.StreamEventCallback

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# StreamEventCallback

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/media/AudioTrack.StreamEventCallback "View this page in Java")  

```
abstract class StreamEventCallback
```

|---|----------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                               ||
| ↳ | [android.media.AudioTrack.StreamEventCallback](https://developer.android.com/reference/kotlin/android/media/AudioTrack.StreamEventCallback#) |

Abstract class to receive event notifications about the stream playback in offloaded mode. See[AudioTrack.registerStreamEventCallback(Executor, StreamEventCallback)](https://developer.android.com/reference/kotlin/android/media/AudioTrack#registerStreamEventCallback(java.util.concurrent.Executor,%20android.media.AudioTrack.StreamEventCallback))to register the callback on the given[AudioTrack](https://developer.android.com/reference/kotlin/android/media/AudioTrack)instance.

## Summary

|                                                                  Public constructors                                                                   ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [StreamEventCallback](https://developer.android.com/reference/kotlin/android/media/AudioTrack.StreamEventCallback#StreamEventCallback())`()` <br /> |

|                                                                                                                                                                                                                                                                       Public methods                                                                                                                                                                                                                                                                       ||
|----------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onDataRequest](https://developer.android.com/reference/kotlin/android/media/AudioTrack.StreamEventCallback#onDataRequest(android.media.AudioTrack,%20kotlin.Int))`(`track:` `[AudioTrack](https://developer.android.com/reference/kotlin/android/media/AudioTrack)`, `sizeInFrames:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Called when more audio data can be written without blocking on an offloaded track.                  |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onPresentationEnded](https://developer.android.com/reference/kotlin/android/media/AudioTrack.StreamEventCallback#onPresentationEnded(android.media.AudioTrack))`(`track:` `[AudioTrack](https://developer.android.com/reference/kotlin/android/media/AudioTrack)`)` Called when all the buffers of an offloaded track that were queued in the audio system (e.g. the combination of the Android audio framework and the device's audio hardware) have been played after |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onTearDown](https://developer.android.com/reference/kotlin/android/media/AudioTrack.StreamEventCallback#onTearDown(android.media.AudioTrack))`(`track:` `[AudioTrack](https://developer.android.com/reference/kotlin/android/media/AudioTrack)`)` Called when an offloaded track is no longer valid and has been discarded by the system.                                                                                                                               |

## Public constructors

### StreamEventCallback

```
StreamEventCallback()
```

## Public methods

### onDataRequest

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onDataRequest(
    track: AudioTrack, 
    sizeInFrames: Int
): Unit
```

Called when more audio data can be written without blocking on an offloaded track.

|                                                                                                                       Parameters                                                                                                                       ||
|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `track`        | [AudioTrack](https://developer.android.com/reference/kotlin/android/media/AudioTrack):the[AudioTrack](https://developer.android.com/reference/kotlin/android/media/AudioTrack)on which the event happened. This value cannot be`null`. |
| `sizeInFrames` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the number of frames available to write without blocking. Note that the frame size of a compressed stream is 1 byte. Value is 0 or greater                  |

### onPresentationEnded

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onPresentationEnded(track: AudioTrack): Unit
```

Called when all the buffers of an offloaded track that were queued in the audio system (e.g. the combination of the Android audio framework and the device's audio hardware) have been played after[AudioTrack.stop()](https://developer.android.com/reference/kotlin/android/media/AudioTrack#stop())has been called.

|                                                                                                                   Parameters                                                                                                                    ||
|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `track` | [AudioTrack](https://developer.android.com/reference/kotlin/android/media/AudioTrack):the[AudioTrack](https://developer.android.com/reference/kotlin/android/media/AudioTrack)on which the event happened. This value cannot be`null`. |

### onTearDown

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onTearDown(track: AudioTrack): Unit
```

Called when an offloaded track is no longer valid and has been discarded by the system. An example of this happening is when an offloaded track has been paused too long, and gets invalidated by the system to prevent any other offload.

|                                                                                                                   Parameters                                                                                                                    ||
|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `track` | [AudioTrack](https://developer.android.com/reference/kotlin/android/media/AudioTrack):the[AudioTrack](https://developer.android.com/reference/kotlin/android/media/AudioTrack)on which the event happened. This value cannot be`null`. |