The AudioPlayer component handles audio playback in the game. It manages playing, pausing and stopping audio sources, controls volume and looping behavior, and can optionally sync playback speed with the game's time scale.

const audioPlayer = new AudioPlayer({
audioSource: "sound.mp3",
volume: 0.5,
loop: true,
fixedToTimeScale: false
});

Constructors

Properties

_playAfterUserInput: boolean = false
_playPromisePendind: boolean = false
action: AudioPlayerAction = undefined

The action to perform with the audio source. This action will be erased at the end of the frame

audioSource: string | HTMLAudioElement

The audio source to play.

fixedToTimeScale: boolean = false

TRUE If the playback rate is fixed to the TimeManager time scale, default FALSE

loop: boolean = false

TRUE If the audio source should loop.

state: AudioPlayerState = "stopped"

READONLY, The current state of the audio source.

stopOnSceneTransition: boolean = true

TRUE If the audio source should stop on scene transition, FALSE otherwise. Default is TRUE.

volume: number = 1

The volume of the audio source.

Accessors

Methods