audioEngine.d.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import type { Analyser } from "./analyser";
  2. import type { Nullable } from "../types";
  3. import { Observable } from "../Misc/observable";
  4. import type { IAudioEngine } from "./Interfaces/IAudioEngine";
  5. /**
  6. * This represents the default audio engine used in babylon.
  7. * It is responsible to play, synchronize and analyse sounds throughout the application.
  8. * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic
  9. */
  10. export declare class AudioEngine implements IAudioEngine {
  11. private _audioContext;
  12. private _audioContextInitialized;
  13. private _muteButton;
  14. private _hostElement;
  15. private _audioDestination;
  16. /**
  17. * Gets whether the current host supports Web Audio and thus could create AudioContexts.
  18. */
  19. canUseWebAudio: boolean;
  20. /**
  21. * The master gain node defines the global audio volume of your audio engine.
  22. */
  23. masterGain: GainNode;
  24. /**
  25. * Defines if Babylon should emit a warning if WebAudio is not supported.
  26. * @ignoreNaming
  27. */
  28. WarnedWebAudioUnsupported: boolean;
  29. /**
  30. * Gets whether or not mp3 are supported by your browser.
  31. */
  32. isMP3supported: boolean;
  33. /**
  34. * Gets whether or not ogg are supported by your browser.
  35. */
  36. isOGGsupported: boolean;
  37. /**
  38. * Gets whether audio has been unlocked on the device.
  39. * Some Browsers have strong restrictions about Audio and won't autoplay unless
  40. * a user interaction has happened.
  41. */
  42. unlocked: boolean;
  43. /**
  44. * Defines if the audio engine relies on a custom unlocked button.
  45. * In this case, the embedded button will not be displayed.
  46. */
  47. useCustomUnlockedButton: boolean;
  48. /**
  49. * Event raised when audio has been unlocked on the browser.
  50. */
  51. onAudioUnlockedObservable: Observable<IAudioEngine>;
  52. /**
  53. * Event raised when audio has been locked on the browser.
  54. */
  55. onAudioLockedObservable: Observable<IAudioEngine>;
  56. /**
  57. * Gets the current AudioContext if available.
  58. */
  59. get audioContext(): Nullable<AudioContext>;
  60. private _connectedAnalyser;
  61. /**
  62. * Instantiates a new audio engine.
  63. *
  64. * There should be only one per page as some browsers restrict the number
  65. * of audio contexts you can create.
  66. * @param hostElement defines the host element where to display the mute icon if necessary
  67. * @param audioContext defines the audio context to be used by the audio engine
  68. * @param audioDestination defines the audio destination node to be used by audio engine
  69. */
  70. constructor(hostElement?: Nullable<HTMLElement>, audioContext?: Nullable<AudioContext>, audioDestination?: Nullable<AudioDestinationNode | MediaStreamAudioDestinationNode>);
  71. /**
  72. * Flags the audio engine in Locked state.
  73. * This happens due to new browser policies preventing audio to autoplay.
  74. */
  75. lock(): void;
  76. /**
  77. * Unlocks the audio engine once a user action has been done on the dom.
  78. * This is helpful to resume play once browser policies have been satisfied.
  79. */
  80. unlock(): void;
  81. private _resumeAudioContext;
  82. private _initializeAudioContext;
  83. private _tryToRun;
  84. private _triggerRunningState;
  85. private _triggerSuspendedState;
  86. private _displayMuteButton;
  87. private _moveButtonToTopLeft;
  88. private _onResize;
  89. private _hideMuteButton;
  90. /**
  91. * Destroy and release the resources associated with the audio context.
  92. */
  93. dispose(): void;
  94. /**
  95. * Gets the global volume sets on the master gain.
  96. * @returns the global volume if set or -1 otherwise
  97. */
  98. getGlobalVolume(): number;
  99. /**
  100. * Sets the global volume of your experience (sets on the master gain).
  101. * @param newVolume Defines the new global volume of the application
  102. */
  103. setGlobalVolume(newVolume: number): void;
  104. /**
  105. * Connect the audio engine to an audio analyser allowing some amazing
  106. * synchronization between the sounds/music and your visualization (VuMeter for instance).
  107. * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#using-the-analyser
  108. * @param analyser The analyser to connect to the engine
  109. */
  110. connectToAnalyser(analyser: Analyser): void;
  111. }