Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AudioEngine

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/how_to/playing_sounds_and_music

Hierarchy

  • AudioEngine

Implements

Index

Constructors

constructor

  • new AudioEngine(hostElement?: Nullable<HTMLElement>, audioContext?: Nullable<AudioContext>, audioDestination?: Nullable<AudioDestinationNode | MediaStreamAudioDestinationNode>): AudioEngine
  • Instantiates a new audio engine.

    There should be only one per page as some browsers restrict the number of audio contexts you can create.

    Parameters

    • Optional hostElement: Nullable<HTMLElement>

      defines the host element where to display the mute icon if necessary

    • Optional audioContext: Nullable<AudioContext>

      defines the audio context to be used by the audio engine

    • Optional audioDestination: Nullable<AudioDestinationNode | MediaStreamAudioDestinationNode>

      defines the audio destination node to be used by audio engine

    Returns AudioEngine

Properties

WarnedWebAudioUnsupportedSearch playground for WarnedWebAudioUnsupported

WarnedWebAudioUnsupported: boolean

Defines if Babylon should emit a warning if WebAudio is not supported.

ignorenaming

canUseWebAudioSearch playground for canUseWebAudio

canUseWebAudio: boolean

Gets whether the current host supports Web Audio and thus could create AudioContexts.

isMP3supportedSearch playground for isMP3supported

isMP3supported: boolean

Gets whether or not mp3 are supported by your browser.

isOGGsupportedSearch playground for isOGGsupported

isOGGsupported: boolean

Gets whether or not ogg are supported by your browser.

masterGainSearch playground for masterGain

masterGain: GainNode

The master gain node defines the global audio volume of your audio engine.

onAudioLockedObservableSearch playground for onAudioLockedObservable

onAudioLockedObservable: Observable<IAudioEngine>

Event raised when audio has been locked on the browser.

onAudioUnlockedObservableSearch playground for onAudioUnlockedObservable

onAudioUnlockedObservable: Observable<IAudioEngine>

Event raised when audio has been unlocked on the browser.

unlockedSearch playground for unlocked

unlocked: boolean

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.

useCustomUnlockedButtonSearch playground for useCustomUnlockedButton

useCustomUnlockedButton: boolean

Defines if the audio engine relies on a custom unlocked button. In this case, the embedded button will not be displayed.

Accessors

audioContext

  • get audioContext(): Nullable<AudioContext>
  • Gets the current AudioContext if available.

    Returns Nullable<AudioContext>

Methods

connectToAnalyserSearch playground for connectToAnalyser

  • connectToAnalyser(analyser: Analyser): void

disposeSearch playground for dispose

  • dispose(): void
  • Destroy and release the resources associated with the audio context.

    Returns void

getGlobalVolumeSearch playground for getGlobalVolume

  • getGlobalVolume(): number
  • Gets the global volume sets on the master gain.

    Returns number

    the global volume if set or -1 otherwise

lockSearch playground for lock

  • lock(): void
  • Flags the audio engine in Locked state. This happens due to new browser policies preventing audio to autoplay.

    Returns void

setGlobalVolumeSearch playground for setGlobalVolume

  • setGlobalVolume(newVolume: number): void
  • 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

unlockSearch playground for unlock

  • unlock(): void
  • 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

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Static property
  • Static method