Player

High-level wrapper around AudioPlaybackSession providing a simplified API.

Example Usage

val player = Kodio.player()

// Load and play a recording
player.load(recording)
player.start()

// Control playback
player.pause()
player.resume()
player.stop()

// Clean up
player.release()

// Or use with structured concurrency
Kodio.play(recording) { player ->
player.start()
player.awaitComplete()
} // auto-released

Seek

seekTo forwards to the session's optional native seek. When it returns SeekResult.Unsupported and supportsTransportSeek is false, callers (e.g. Compose space.kodio.compose.PlayerState) may fall back to reloading a clipped AudioRecording window. Transport sessions treat Unsupported as out-of-window only.

Constructors

Link copied to clipboard
constructor(session: AudioPlaybackSession)

Properties

Link copied to clipboard

Currently retained seekable window. Empty if nothing buffered.

Link copied to clipboard

Whether playback has finished.

Link copied to clipboard

Whether the player is paused.

Link copied to clipboard

Whether the player is currently playing audio.

Link copied to clipboard

Whether the player is ready to play (has audio loaded). This includes Ready, Paused, and Finished states where audio is available.

Link copied to clipboard
val position: StateFlow<Duration>

Transport media time, best-effort while playing. Frozen at Duration.ZERO on sessions that have not migrated to transport.

Link copied to clipboard

The current unified state of the player.

Link copied to clipboard

Flow of state changes for observing the player.

Link copied to clipboard

Whether the underlying session implements transport-buffer seek. When true, SeekResult.Unsupported means out-of-window, not "use PCM fallback".

Functions

Link copied to clipboard
suspend fun awaitComplete()

Waits for playback to complete (finish or error).

Link copied to clipboard
suspend fun load(recording: AudioRecording)

Loads an AudioRecording for playback.

Link copied to clipboard
suspend fun loadAudioFlow(audioFlow: AudioFlow)

Loads an AudioFlow for playback (legacy compatibility).

Link copied to clipboard
fun pause()

Pauses playback. Can be resumed with resume.

Link copied to clipboard
fun release()

Releases resources associated with this player. The player should not be used after calling this method.

Link copied to clipboard
fun resume()

Resumes paused playback.

Link copied to clipboard
fun seekTo(position: Duration): SeekResult

Attempts a platform-native seek to position.

Link copied to clipboard
suspend fun start()

Starts playback.

Link copied to clipboard
fun stop()

Stops playback and resets to the beginning.

Link copied to clipboard
suspend fun toggle(): Boolean?

Toggles between playing and paused states.

Link copied to clipboard

Access the underlying session for advanced use cases.

Link copied to clipboard
inline fun <T> Player.use(block: (Player) -> T): T

Extension for using Player with Kotlin's use pattern. Ensures proper cleanup even if an exception occurs.