AudioPlaybackSession

Represents an active playback session.

Seek capability

seekTo is an optional native transport capability. The default implementation returns SeekResult.Unsupported. Platforms that wire PlaybackBuffer-backed transport override it and return SeekResult.Applied when the target is inside bufferedRange, or ahead of ingest on known-finite content (pending cursor). Live/unbounded flows must never be fully collected for seek; seek outside the retained window returns SeekResult.Unsupported.

When seekTo returns SeekResult.Unsupported on a session with supportsTransportSeek false, higher layers may fall back to a portable approach (Compose space.kodio.compose.PlayerState reloads a clipped PCM window). Transport sessions publish bufferedRange; out-of-window seeks stay SeekResult.Unsupported without inventing a second timeline.

knownByteCount / AudioFlow.isKnownFinite are length metadata and growable eligibility, not the sole seek gate.

Inheritors

Types

Link copied to clipboard
sealed class State

Represents the state of a playback session.

Properties

Link copied to clipboard
abstract val audioFlow: StateFlow<AudioFlow?>

A flow that emits the current loaded audio data.

Link copied to clipboard
open val bufferedRange: StateFlow<BufferedRange>

Currently retained seekable window. Empty if nothing buffered. Defaults to a frozen empty range for unmigrated sessions.

Link copied to clipboard
open val position: StateFlow<Duration>

Transport media time, best-effort while playing. Defaults to a frozen Duration.ZERO for unmigrated sessions.

Link copied to clipboard
abstract val state: StateFlow<AudioPlaybackSession.State>

A flow that emits the current state of the playback.

Link copied to clipboard

true when this session implements PlaybackBuffer-backed seek (bufferedRange / pending-cursor). Compose uses this to skip the PCM-window fallback even before the first non-empty bufferedRange is published.

Functions

Link copied to clipboard
abstract suspend fun load(audioFlow: AudioFlow)

Loads the given audio data.

Link copied to clipboard
abstract fun pause()

Pauses the playback.

Link copied to clipboard
abstract suspend fun play()

Starts playback of the given audio data.

Link copied to clipboard
open fun release()

Stops playback and frees the session's resources (background coroutines, device handles). The session must not be used afterwards.

Link copied to clipboard
abstract fun resume()

Resumes paused playback.

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

Move the transport read cursor.

Link copied to clipboard
abstract fun stop()

Stops the playback entirely.