Playback
Kodio provides several playback APIs, from recording.play() to a Player class with pause, resume, and device selection.
Simple playback
To play audio, call play() on a recording. This suspends until playback completes:
Playback with controls
When you need to pause, resume, or monitor playback, use Kodio.play() with a lambda:
The lambda receives a Player instance that gives you full control over playback.
Using Player directly
For more control, create a Player instance directly. This is useful for:
Loading different recordings into the same player
Managing the player's lifecycle explicitly
Building custom playback UIs
Output device selection
Play audio to a specific output device (headphones, speakers, etc.):
Player API reference
Properties
- isPlaying: Boolean
truewhile audio is actively playing.- isPaused: Boolean
trueif playback was started and then paused.- isReady: Boolean
truewhen audio is loaded and ready to play.- isFinished: Boolean
trueafter playback has completed.- stateFlow: StateFlow<State>
Observable state changes for reactive UIs.
Methods
- load(recording)
Load an
AudioRecordingfor playback.- start()
Begin or resume playback.
- pause()
Pause playback. Use
resume()to continue.- resume()
Continue playback after pausing.
- stop()
Stop playback and reset to the beginning.
- toggle()
Play if stopped/paused, pause if playing. Useful for single-button UIs.
- release()
Release all resources. Called automatically when using
use {}.- awaitComplete()
Suspend until playback finishes.