Nucleus
Media player

AudioNew

Play music, podcasts and the sound of any media with AudioPlayer, on the platform's decoders, without decoding a picture.

View as Markdown

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-playermacOSWindowsLinuxAndroidiOSWebDesktop Gradle plugin: Not neededDesktop window runtime: Not needed

Add the dependency

build.gradle.kts
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 done

In 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 = 6f

What's next

Was this page helpful?
Edit on GitHub

Last updated on