SoundAsset
Asset type for loading audio/sound files.
Supports various audio formats depending on the backend:
- Web: MP3, OGG, WAV, M4A
- Native: MP3, OGG, WAV, FLAC
Features:
- Streaming support for large audio files
- Hot reload during development
- Automatic format fallback (tries alternative formats if one fails)
var assets = new Assets();
assets.addSound('music/background');
assets.addSound('sfx/jump', null, {stream: true});
assets.load();
// Play loaded sound
var sound = assets.sound('sfx/jump');
sound.play();
Instance Members
stream: BoolWhether this sound should be streamed from disk rather than loaded into memory. Useful for large audio files like background music. Note: Streaming support depends on the backend.
sound: SoundThe loaded Sound instance. Observable property that updates when the sound is loaded or replaced. Null until the asset is successfully loaded.
invalidateSound(): Voidload(): VoidLoad the sound file. Tries multiple file formats if available, falling back to alternatives on failure. Emits complete event when finished.
destroy(): Voidnew(name: String, ?variant: String, ?options: Null<AssetOptions>): VoidCreate a new sound asset.
| Name | Type | Default | Description |
|---|---|---|---|
name |
String | Sound file name (with or without extension) | |
variant |
String | (optional) | Optional variant suffix |
options |
Null<AssetOptions> | (optional) | Loading options including: - stream: Whether to stream the audio - volume: Initial volume (0.0 to 1.0) |
Private Members
unobservedSound: SoundEmitted when the sound is replaced (e.g., during hot reload).
| Name | Type | Description |
|---|---|---|
newSound |
Sound | The newly loaded sound |
prevSound |
Sound | The previous sound being replaced |
Event when sound field changes.
| Name | Type |
|---|---|
current |
Sound |
previous |
Sound |
assetFilesDidChange(newFiles: ReadOnlyMap<String, Float>, previousFiles: ReadOnlyMap<String, Float>): VoidHandle file system changes for hot reload. Automatically reloads the sound when the source file is modified.
| Name | Type |
|---|---|
newFiles |
ReadOnlyMap<String, Float> |
previousFiles |
ReadOnlyMap<String, Float> |
Metadata
| Name | Parameters |
|---|---|
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |
:build |
tracker.macros.ObservableMacro.build() |
:autoBuild |
tracker.macros.ObservableMacro.build() |