Stay organized with collections
Save and categorize content based on your preferences.
StreamEventCallback
abstract class StreamEventCallback
Abstract class to receive event notifications about the stream playback in offloaded mode. See AudioTrack.registerStreamEventCallback(Executor, StreamEventCallback)
to register the callback on the given AudioTrack
instance.
Summary
Public methods |
open Unit |
Called when more audio data can be written without blocking on an offloaded track.
|
open 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
|
open Unit |
Called when an offloaded track is no longer valid and has been discarded by the system.
|
Public constructors
StreamEventCallback
StreamEventCallback()
Public methods
onDataRequest
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: the AudioTrack on which the event happened. This value cannot be null . |
sizeInFrames |
Int: 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
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()
has been called.
onTearDown
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.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# AudioTrack.StreamEventCallback\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nStreamEventCallback\n===================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/media/AudioTrack.StreamEventCallback \"View this page in Java\") \n\n```\nabstract class StreamEventCallback\n```\n\n|---|---------------------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.media.AudioTrack.StreamEventCallback](#) |\n\nAbstract class to receive event notifications about the stream playback in offloaded mode. See [AudioTrack.registerStreamEventCallback(Executor, StreamEventCallback)](/reference/kotlin/android/media/AudioTrack#registerStreamEventCallback(java.util.concurrent.Executor,%20android.media.AudioTrack.StreamEventCallback)) to register the callback on the given [AudioTrack](/reference/kotlin/android/media/AudioTrack) instance.\n\nSummary\n-------\n\n| Public constructors ||\n|----------------------------------------------------------|---|\n| [StreamEventCallback](#StreamEventCallback())`()` \u003cbr /\u003e |\n\n| Public methods ||\n|-----------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onDataRequest](#onDataRequest(android.media.AudioTrack,%20kotlin.Int))`(`track:` `[AudioTrack](/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. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onPresentationEnded](#onPresentationEnded(android.media.AudioTrack))`(`track:` `[AudioTrack](/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 |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onTearDown](#onTearDown(android.media.AudioTrack))`(`track:` `[AudioTrack](/reference/kotlin/android/media/AudioTrack)`)` Called when an offloaded track is no longer valid and has been discarded by the system. |\n\nPublic constructors\n-------------------\n\n### StreamEventCallback\n\n```\nStreamEventCallback()\n```\n\nPublic methods\n--------------\n\n### onDataRequest\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun onDataRequest(\n track: AudioTrack, \n sizeInFrames: Int\n): Unit\n```\n\nCalled when more audio data can be written without blocking on an offloaded track.\n\n| Parameters ||\n|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `track` | [AudioTrack](/reference/kotlin/android/media/AudioTrack): the [AudioTrack](/reference/kotlin/android/media/AudioTrack) on which the event happened. This value cannot be `null`. |\n| `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 |\n\n### onPresentationEnded\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun onPresentationEnded(track: AudioTrack): Unit\n```\n\nCalled 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()](/reference/kotlin/android/media/AudioTrack#stop()) has been called.\n\n| Parameters ||\n|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `track` | [AudioTrack](/reference/kotlin/android/media/AudioTrack): the [AudioTrack](/reference/kotlin/android/media/AudioTrack) on which the event happened. This value cannot be `null`. |\n\n### onTearDown\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun onTearDown(track: AudioTrack): Unit\n```\n\nCalled 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.\n\n| Parameters ||\n|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `track` | [AudioTrack](/reference/kotlin/android/media/AudioTrack): the [AudioTrack](/reference/kotlin/android/media/AudioTrack) on which the event happened. This value cannot be `null`. |"]]