SoundAsset

EntityAssetceramic.SoundAsset (Class)

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: Bool

Whether 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: Sound

The loaded Sound instance. Observable property that updates when the sound is loaded or replaced. Null until the asset is successfully loaded.


invalidateSound(): Void

load(): Void

Load the sound file. Tries multiple file formats if available, falling back to alternatives on failure. Emits complete event when finished.


destroy(): Void

new(name: String, ?variant: String, ?options: Null<AssetOptions>): Void

Create 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: Sound

emitReplaceSound(newSound: Sound, prevSound: Sound): Void

Emitted 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

emitSoundChange(current: Sound, previous: Sound): Void

Event when sound field changes.

Name Type
current Sound
previous Sound

assetFilesDidChange(newFiles: ReadOnlyMap<String, Float>, previousFiles: ReadOnlyMap<String, Float>): Void

Handle 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()