Audio
Updated
Plays a sound heard the same everywhere, for music or UI.
- Type
comp-audio- Script class
AudioComponent- Per entity
- One
- Version
- 1.0.0
Read about it in Audio sources: what it does, how to use it from a script, and examples.
Properties
Section titled “Properties”The props the runtime declares for this component, with their defaults and accepted ranges.
| Prop | Default | Range |
|---|---|---|
volume |
0 ≤ x ≤ 1 |
Events
Section titled “Events”Sent to the entity’s Signal Emitter as { entityId, eventType, data }. Compare eventType with the EventType constants.
Audio::readyAudio::errorAudio::playAudio::pauseAudio::stopAudio::end
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
Live example
Pause and resume musicYour first sound: background music on an Audio entity, and a radio that pauses and resumes it when clicked, with the source’s own events in the log.
With your sound on, click the radio to pause the music, and again to resume it.
From a script
Section titled “From a script”#pragma lifecycle(startup)
function startup() { const component = self.parent.getComponent(AudioComponent); if (component) log(component.props);}