SonixPlayerConfig

data class SonixPlayerConfig(val volume: Float = 1.0f, val pitch: Float = 0.0f, val tempo: Float = 1.0f, val loopCount: Int = 1, val onComplete: () -> Unit? = null, val onLoopComplete: (loopIndex: Int, totalLoops: Int) -> Unit? = null, val onPlaybackStateChanged: (isPlaying: Boolean) -> Unit? = null, val onError: (message: String) -> Unit? = null)

Configuration for SonixPlayer.

Usage Tiers

Tier 1: Presets (80% of users)

Kotlin

val player = SonixPlayer.create("song.mp3", SonixPlayerConfig.DEFAULT)

Swift

let player = try await SonixPlayer.create(source: "song.mp3", config: .default)

Tier 2: Builder (15% of users)

Kotlin

val config = SonixPlayerConfig.Builder()
.preset(SonixPlayerConfig.LOOPING)
.volume(0.8f)
.pitch(-2f)
.build()
val player = SonixPlayer.create("song.mp3", config)

Swift

let config = SonixPlayerConfig.Builder()
.preset(.looping)
.volume(0.8)
.pitch(-2)
.build()
let player = try await SonixPlayer.create(source: "song.mp3", config: config)

Tier 3: .copy() (5% of users)

Kotlin

val config = SonixPlayerConfig.LOOPING.copy(volume = 0.5f)

See also

Factory method to create players

For recording audio

Constructors

Link copied to clipboard
constructor(volume: Float = 1.0f, pitch: Float = 0.0f, tempo: Float = 1.0f, loopCount: Int = 1, onComplete: () -> Unit? = null, onLoopComplete: (loopIndex: Int, totalLoops: Int) -> Unit? = null, onPlaybackStateChanged: (isPlaying: Boolean) -> Unit? = null, onError: (message: String) -> Unit? = null)

Types

Link copied to clipboard
class Builder

Builder for SonixPlayerConfig.

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Loop count (1 = play once, -1 = infinite)

Link copied to clipboard
val onComplete: () -> Unit?

Called when playback completes (all loops finished)

Link copied to clipboard
val onError: (message: String) -> Unit?

Called on playback errors

Link copied to clipboard
val onLoopComplete: (loopIndex: Int, totalLoops: Int) -> Unit?

Called when a loop iteration completes

Link copied to clipboard
val onPlaybackStateChanged: (isPlaying: Boolean) -> Unit?

Called when playback state changes

Link copied to clipboard

Pitch shift in semitones (-12 to +12)

Link copied to clipboard

Tempo/speed multiplier (0.25 to 4.0, 1.0 = normal)

Link copied to clipboard

Initial volume (0.0 to 1.0)