Skip to content
Merged
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
45 changes: 45 additions & 0 deletions apps/radio/src/lib/audio/manager/audio-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,51 @@ describe("AudioManager", () => {
}
);

// RADIO-23: single-mode external stream replacement. load() queues an abort
// for the previous resource; treating that media event as failure reported
// AbortError "Load aborted" as PLAY_ERROR while the replacement was current.
test("a playing single-mode stream replacement ignores a queued media abort", async () => {
const harness = createMediaPlaybackHarness();
try {
const { manager, browser } = harness;
const soundId = manager.createSound(station, "single:station", "native");
const states: AudioState[] = [];
manager.subscribe(soundId, (state) => states.push(state));
const starting = manager.playSound(soundId);
await flushMicrotasks();
const audio = browser.audio();
audio.emit("canplay");
await starting;
audio.emit("playing");
expect(audio.paused).toBe(false);

const emptyReadyState = HTMLMediaElement.HAVE_NOTHING;
audio.load = () => {
audio.readyState = emptyReadyState;
};
const nextUrl = "https://radio.example/replacement.mp3";
const refreshing = manager
.refreshStreamUrl(soundId, nextUrl)
.catch((error: unknown) => error);
await flushMicrotasks();
const stateCount = states.length;
audio.emit("abort");
audio.emit("canplay");
expect(await refreshing).toBeUndefined();

expect(audio.src).toBe(nextUrl);
expect(audio.paused).toBe(false);
expect(states.slice(stateCount).some((state) => state.error)).toBe(false);
expect(states.at(-1)).toMatchObject({
error: null,
isLoading: false,
isPlaying: true,
});
} finally {
harness.restore();
}
});

test.each(["audio-graph", "native"] as const)(
"a recreated %s source seeks before its first playback",
async (mode) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ afterEach(() => {
});

describe("MediaElementPlaybackSource native playback", () => {
// RADIO-23: a browser abort for the previous resource must not reject the
// current load as AbortError "Load aborted" (reported upstream as PLAY_ERROR).
test("a queued abort from the previous resource does not fail its replacement", async () => {
const browser = installBrowser();
const onError = mock(() => undefined);
Expand Down
Loading