AudioNew
Play music, podcasts and the sound of any media with AudioPlayer, on the platform's decoders, without decoding a picture.
AudioPlayer plays audio with the platform's own decoders: no extra codec library. MP3, AAC
(M4A), FLAC and WAV play on every platform. It runs on the same engine as the video player, so
playlists, streaming formats, offline playback and the system's media controls work the same.
audio-playerDesktop Gradle plugin: Not neededDesktop window runtime: Not neededAdd the dependency
commonMain.dependencies {
implementation("dev.nucleusframework:nucleus.audio-player:3.0.0")
}Play a file
val player = AudioPlayer()
player.play("https://example.com/episode.mp3")
player.pause()
player.seekTo(90_000) // milliseconds
player.setVolume(0.8f)
player.setRate(1.5f)
player.release() // when you are doneIn Compose, rememberAudioPlayerLiveState() gives a remembered player and a snapshot of its
state (state, position, duration, volume) that recomposes as it plays, and releases the
player on dispose:
val live = rememberAudioPlayerLiveState()
Text("${live.position / 1000} s")
Button(onClick = { live.player.play(url) }) { Text("Play") }state is IDLE, BUFFERING, PLAYING or PAUSED. Errors arrive in error and through
setOnErrorListener, called once per error.
The sound of a video
AudioPlayer plays the sound of a video file without decoding its picture: ExoPlayer disables
its video track, Media Foundation runs an audio-only engine, GStreamer builds no video branch, AVFoundation disables the item's
video tracks, the web uses an <audio> element.
A podcast published as video costs no video decoder.
The full engine
player.playback is the MediaPlaybackState underneath. Everything the
playback control page describes is there: playlists, seek modes,
silence skipping, loudness and equalizer, stats.
player.playback.skipSilence = true
player.playback.loudnessGainDb = 6fWhat's next
- Playback control: playlists, speed, silences, loudness and equalizer.
- System session: lock screen, notification and media keys.
- Offline: keep episodes on the device.
Last updated on
Video
Show a video with VideoPlayerSurface, build controls on VideoPlayerState, and add fullscreen, subtitles, picture-in-picture and thumbnails.
Streaming
Play HLS, MPEG-DASH and Smooth Streaming, live streams with a DVR window, audio languages, video variants, subtitles, request headers and timed metadata.