Class
AudioPlugin
View sourceExtendsPlugin
Adds browser audio playback to an App.
It connects AudioPlayer and AudioOscillator components to
Audio assets and provides the AudioGraph,
AudioCommands, and AudioAssets resources. Use
AudioPlayer for entity audio, AudioOscillator for
generated waveforms, and AudioCommands for direct controls.
Audio assets are available through AudioAssets and can be imported
with AudioImporter using browser-supported audio formats. It also
provides AudioAdded, AudioModified, and
AudioDropped for asset lifecycle changes. Register
AssetServerPlugin when audio assets should be loaded through the
asset server.
Component and command playback use separate browser audio contexts. The
plugin directly requires CorePlugin, ReflectPlugin, and
TimePlugin. Its asset importer also requires
AssetServerPlugin.
Examples
import { App } from '@wimaengine/app'
import { AssetServerPlugin } from '@wimaengine/asset'
import { AudioPlugin } from '@wimaengine/audio'
import { CorePlugin } from '@wimaengine/core'
import { ReflectPlugin } from '@wimaengine/reflect'
import { TimePlugin } from '@wimaengine/time'
new App()
.registerPlugin(new ReflectPlugin())
.registerPlugin(new CorePlugin())
.registerPlugin(new TimePlugin())
.registerPlugin(new AssetServerPlugin())
.registerPlugin(new AudioPlugin())
.setRunner(() => {})
.run()Constructor
Methods
register(app: App): void
View sourceAdds audio resources, component cleanup behavior, and asset integration to an app.
The hook for AudioPlayer drops its audio handle and stops the
current source when the component is removed. The hook for
AudioOscillator stops its current oscillator. Neither component
receives an add or insert hook.
The app receives an AudioGraph and an AudioCommands
resource in its default world. The graph drives component-based playback,
while commands provide imperative play, stop, mute, and unmute controls.
It registers an AssetPlugin for Audio with
AudioAdded, AudioModified, and AudioDropped
lifecycle events, and an AssetImporterPlugin containing
AudioImporter. The importer advertises browser-supported audio
extensions and decodes fetched responses into Audio assets.
AudioAssets provides the typed view of those assets.
AudioPlayer resolves its audio handle through AudioAssets
and AudioOscillator creates waveform sources through the graph.
Browser autoplay restrictions can leave either context suspended. The
plugin resumes both contexts after a pointerdown interaction and removes
each listener once its context reports running.
requires(): TypeId[]
View sourceReturns the plugins required directly by audio support.
The direct dependencies are CorePlugin,
ReflectPlugin, and TimePlugin. The nested
AssetImporterPlugin also requires AssetServerPlugin;
register that plugin when audio assets should be loaded through the asset
server. Dependencies are validated by the app and are not installed
automatically.
