Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions __TEST__/hyperaudio-lite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,24 @@ test("registerPlayer() adds a custom player type (#253)", () => {
delete hyperaudioPlayerOptions.fake;
});

test("NativePlayer stays paused when browser playback is rejected (#268)", async () => {
const inst = new HyperaudioLite({
transcript: "hypertranscript",
player: "hyperplayer",
});
const rejectedPlay = Promise.reject(new DOMException("Autoplay blocked", "NotAllowedError"));
rejectedPlay.catch(() => {});
const playSpy = jest.spyOn(inst.player, "play").mockReturnValue(rejectedPlay);

inst.myPlayer.paused = true;
inst.myPlayer.play();
await Promise.resolve();

expect(inst.myPlayer.paused).toBe(true);

playSpy.mockRestore();
inst.destroy();
});



8 changes: 6 additions & 2 deletions js/hyperaudio-lite.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ class NativePlayer extends BasePlayer {
}

play() {
this.player.play();
this.paused = false;
const playPromise = this.player.play();
if (playPromise && typeof playPromise.catch === 'function') {
playPromise.catch(() => {
this.paused = true;
});
}
}

pause() {
Expand Down
8 changes: 6 additions & 2 deletions js/hyperaudio-lite.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ class NativePlayer extends BasePlayer {
}

play() {
this.player.play();
this.paused = false;
const playPromise = this.player.play();
if (playPromise && typeof playPromise.catch === 'function') {
playPromise.catch(() => {
this.paused = true;
});
}
}

pause() {
Expand Down
Loading