API reference
API reference
Select your platform
No SDKs available
No versions available

SceneAudioPlayer

SceneAudioPlayer

class SceneAudioPlayer
Controls playback of spatial audio in a 3D scene with dynamic control capabilities.
Unlike the direct playSound methods in Scene, SceneAudioPlayer provides ongoing control over audio playback, allowing you to start, stop, and update properties like volume and position while the sound is playing.
Example usage:
// Load an audio asset
val audioAsset = SceneAudioAsset.loadLocalFile("data/common/audio/ambient.ogg")

// Create an audio player for the asset
val audioPlayer = SceneAudioPlayer(scene, audioAsset)

// Play the sound at a specific position with looping enabled
audioPlayer.play(
    position = Vector3(0f, 1.7f, -2f),
    volume = 0.8f,
    looping = true
)

// Later, update the volume
audioPlayer.setVolume(0.5f)

// Move the sound to follow an object
audioPlayer.setPosition(objectPosition)

// Stop playback when no longer needed
audioPlayer.stop()
Each SceneAudioPlayer instance is assigned a unique channel name, allowing multiple sounds to be controlled independently.

Constructors

NameSummary
SceneAudioPlayer
constructor(scene: Scene, soundAsset: SceneAudioAsset)

Creates a new audio player for the specified audio asset.

Types

NameSummary
Companion
object Companion

Functions

NameSummary
play
fun play(position: Vector3, volume: Float = 1.0f, looping: Boolean = false)

Starts playing the audio at the specified position.
setPosition
fun setPosition(position: Vector3)

Updates the position of the currently playing audio.
setVolume
fun setVolume(volume: Float)

Adjusts the volume of the currently playing audio.
stop
fun stop()

Stops the audio playback.

Companion

object Companion

Properties

NameSummary
playerCount
var playerCount: Int
Did you find this page helpful?
Thumbs up icon
Thumbs down icon