Class AudioEngine
Implements
Constructors
constructor
-
new AudioEngine(
hostElement?: Nullable<HTMLElement>,
audioContext?: Nullable<AudioContext>,
audioDestination?: Nullable<
AudioDestinationNode
| MediaStreamAudioDestinationNode,
>,
): AudioEngineInstantiates a new audio engine.
Parameters
- hostElement: Nullable<HTMLElement> = null
defines the host element where to display the mute icon if necessary
- audioContext: Nullable<AudioContext> = null
defines the audio context to be used by the audio engine
- audioDestination: Nullable<AudioDestinationNode | MediaStreamAudioDestinationNode> = null
defines the audio destination node to be used by audio engine
Returns AudioEngine
- hostElement: Nullable<HTMLElement> = null
Properties
can Use Web Audio
Gets whether the current host supports Web Audio and thus could create AudioContexts.
is MP3supported
Gets whether or not mp3 are supported by your browser.
is OG Gsupported
Gets whether or not ogg are supported by your browser.
on Audio Locked Observable
Event raised when audio has been locked on the browser.
on Audio Unlocked Observable
Event raised when audio has been unlocked on the browser.
unlocked
Gets whether audio has been unlocked on the device. Some Browsers have strong restrictions about Audio and won't autoplay unless a user interaction has happened.
Warned Web Audio Unsupported
Defines if Babylon should emit a warning if WebAudio is not supported.
Accessors
audio Context
-
Gets the current AudioContext if available.
Returns Nullable<AudioContext>
master Gain
-
get masterGain(): GainNode
The master gain node defines the global audio volume of your audio engine.
Returns GainNode
-
set masterGain(value: GainNode): void
The master gain node defines the global audio volume of your audio engine.
Parameters
- value: GainNode
Returns void
use Custom Unlocked Button
-
get useCustomUnlockedButton(): boolean
Defines if the audio engine relies on a custom unlocked button. In this case, the embedded button will not be displayed.
Returns boolean
-
set useCustomUnlockedButton(value: boolean): void
Defines if the audio engine relies on a custom unlocked button. In this case, the embedded button will not be displayed.
Parameters
- value: boolean
Returns void
Methods
connect To Analyser
-
Connect the audio engine to an audio analyser allowing some amazing synchronization between the sounds/music and your visualization (VuMeter for instance).
Parameters
- analyser: Analyser
The analyser to connect to the engine
Returns void
- analyser: Analyser
dispose
-
Destroy and release the resources associated with the audio context.
Returns void
get Global Volume
-
Gets the global volume sets on the master gain.
Returns number
the global volume if set or -1 otherwise
lock
-
Flags the audio engine in Locked state. This happens due to new browser policies preventing audio to autoplay.
Returns void
set Global Volume
-
Sets the global volume of your experience (sets on the master gain).
Parameters
- newVolume: number
Defines the new global volume of the application
Returns void
- newVolume: number
unlock
-
Unlocks the audio engine once a user action has been done on the dom. This is helpful to resume play once browser policies have been satisfied.
Returns void
This represents the default audio engine used in babylon. It is responsible to play, synchronize and analyse sounds throughout the application.
See
https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic