1- import type { Analyser } from "./analyser" ;
2-
3- import type { Nullable } from "../types" ;
4- import { Observable } from "../Misc/observable" ;
5- import { AbstractEngine } from "../Engines/abstractEngine" ;
6- import type { IAudioEngine } from "./Interfaces/IAudioEngine" ;
71import { _WebAudioEngine } from "../AudioV2/webAudio/webAudioEngine" ;
82import type { _WebAudioMainBus } from "../AudioV2/webAudio/webAudioMainBus" ;
3+ import { AbstractEngine } from "../Engines/abstractEngine" ;
4+ import { Observable } from "../Misc/observable" ;
5+ import type { Nullable } from "../types" ;
6+ import type { Analyser } from "./analyser" ;
7+ import type { IAudioEngine } from "./Interfaces/IAudioEngine" ;
98
109// Sets the default audio engine to Babylon.js
1110AbstractEngine . AudioEngineFactory = (
@@ -22,7 +21,6 @@ AbstractEngine.AudioEngineFactory = (
2221 * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic
2322 */
2423export class AudioEngine implements IAudioEngine {
25- private _audioContext : Nullable < AudioContext > = null ;
2624 private _masterGain : GainNode ;
2725 private _tryToRun = false ;
2826 private _useCustomUnlockedButton : boolean = false ;
@@ -176,7 +174,7 @@ export class AudioEngine implements IAudioEngine {
176174 * This is helpful to resume play once browser policies have been satisfied.
177175 */
178176 public unlock ( ) {
179- if ( this . _audioContext ?. state === "running" ) {
177+ if ( this . _v2 . _audioContext ?. state === "running" ) {
180178 if ( ! this . unlocked ) {
181179 // Notify users that the audio stack is unlocked/unmuted
182180 this . unlocked = true ;
@@ -192,10 +190,10 @@ export class AudioEngine implements IAudioEngine {
192190
193191 /** @internal */
194192 public _resumeAudioContextOnStateChange ( ) : void {
195- this . _audioContext ?. addEventListener (
193+ this . _v2 . _audioContext ?. addEventListener (
196194 "statechange" ,
197195 ( ) => {
198- if ( this . unlocked && this . _audioContext ?. state !== "running" ) {
196+ if ( this . unlocked && this . _v2 . _audioContext ?. state !== "running" ) {
199197 // eslint-disable-next-line @typescript-eslint/no-floating-promises
200198 this . _resumeAudioContextAsync ( ) ;
201199 }
@@ -214,6 +212,10 @@ export class AudioEngine implements IAudioEngine {
214212 return Promise . resolve ( ) ;
215213 }
216214
215+ if ( this . _v2 . _audioContext . state === "suspended" && ! this . _useCustomUnlockedButton ) {
216+ this . _v2 . _unmuteUIEnabled = true ;
217+ }
218+
217219 return this . _v2 . _audioContext . resume ( ) ;
218220 }
219221
0 commit comments