fix audio can't playOneShot on iOS browser (#8117)

* fix audio can't playOneShot on iOS browser

* fix ESLint

* fix ESLint

* fix ESLint

* fix ESLint
This commit is contained in:
PP
2021-01-11 15:22:48 +08:00
committed by GitHub
parent b63d60de90
commit 524837c37a
+13 -2
View File
@@ -51,7 +51,9 @@ class AudioManagerWeb extends AudioManager<ManagedAudio> {
} else {
audioToDiscard = this._playingAudios.shift();
}
audioToDiscard?.stop();
if (audioToDiscard) {
audioToDiscard.stop();
}
}
}
@@ -134,6 +136,13 @@ export class AudioPlayerWeb extends AudioPlayer {
public playOneShot (volume = 1) {
if (!this._nativeAudio) { return; }
if (this._context.state as string === 'interrupted' || this._context.state as string === 'suspended') {
if (this._context.resume) {
this._context.resume().catch((err) => {
console.error(err);
});
}
}
AudioPlayerWeb._manager.discardOnePlayingIfNeeded();
const gainNode = this._context.createGain();
gainNode.connect(this._context.destination);
@@ -245,7 +254,9 @@ export class AudioPlayerWeb extends AudioPlayer {
private _onGesture () {
if (this._context.state !== 'running') {
this._context.resume().then(this._onGestureProceedCB);
this._context.resume().then(this._onGestureProceedCB).catch((err) => {
console.error(err);
});
} else {
this._onGestureProceed();
}