PlayerState
State holder for audio playback in Compose.
Provides a simplified, reactive API for playing audio that integrates with Compose's state management.
Example Usage
@Composable
fun AudioPlayer(recording: AudioRecording) {
val playerState = rememberPlayerState(recording)
Column {
// Show playback status
Text(
when {
playerState.isLoading -> "Loading..."
playerState.isPlaying -> "Playing"
playerState.isPaused -> "Paused"
playerState.isFinished -> "Finished"
else -> "Ready"
}
)
// Play/Pause button
Button(
onClick = { playerState.toggle() },
enabled = playerState.isReady && !playerState.isLoading
) {
Text(if (playerState.isPlaying) "Pause" else "Play")
}
// Stop button
Button(onClick = { playerState.stop() }) {
Text("Stop")
}
}
}Content copied to clipboard
Properties
Functions
Link copied to clipboard
Clears the current error.
Link copied to clipboard
Loads an AudioRecording for playback.
Link copied to clipboard
Loads an AudioRecording for playback (suspend version).
Link copied to clipboard
Resets the player state and unloads any recording (suspend version).
Link copied to clipboard
Toggles between playing and paused states (suspend version).