Wait for audio to play before pausing
This commit is contained in:
parent
a1ab62f878
commit
1dac6ab3d9
1 changed files with 8 additions and 1 deletions
|
@ -3,6 +3,10 @@
|
||||||
|
|
||||||
import { noop } from 'lodash';
|
import { noop } from 'lodash';
|
||||||
|
|
||||||
|
function isAbortError(error: unknown) {
|
||||||
|
return error instanceof DOMException && error.name === 'AbortError';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around a global HTMLAudioElement that can update the
|
* Wrapper around a global HTMLAudioElement that can update the
|
||||||
* source and callbacks without requiring removeEventListener
|
* source and callbacks without requiring removeEventListener
|
||||||
|
@ -67,7 +71,10 @@ class GlobalMessageAudio {
|
||||||
play(): void {
|
play(): void {
|
||||||
this.#playing = true;
|
this.#playing = true;
|
||||||
this.#audio.play().catch(error => {
|
this.#audio.play().catch(error => {
|
||||||
this.#onError(error);
|
// If `audio.pause()` is called before `audio.play()` resolves
|
||||||
|
if (!isAbortError(error)) {
|
||||||
|
this.#onError(error);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue