Skip to content

Commit f865165

Browse files
committed
fix(core): a decoded buffer's handover leaves the routed element silent
1 parent fc0b533 commit f865165

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎packages/core/src/runtime/webAudioTransport.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,20 @@ describe("WebAudioTransport", () => {
195195
expect([transport.routesElement(gone), transport.routesElement(kept)]).toEqual([false, true]);
196196
});
197197

198+
it("keeps a routed element silent once a decoded buffer plays in its place", async () => {
199+
const { transport, mock, gen } = setupTransport(100);
200+
const node = { connect: vi.fn(), disconnect: vi.fn() };
201+
mock.ctx.createMediaElementSource = vi.fn(() => node) as never;
202+
await transport.scheduleMediaElementPlayback(mockEl, 0, 0, 0, 1, gen, 1);
203+
node.connect.mockClear();
204+
node.disconnect.mockClear();
205+
206+
transport.releaseRouted(mockEl);
207+
208+
expect(node.disconnect).toHaveBeenCalled();
209+
expect(node.connect).not.toHaveBeenCalled();
210+
});
211+
198212
it("creates one MediaElementAudioSourceNode per element and context", async () => {
199213
const { transport, mock } = setupTransport(100);
200214

‎packages/core/src/runtime/webAudioTransport.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,12 +1052,13 @@ export class WebAudioTransport {
10521052
}
10531053
}
10541054

1055-
/** Drops the routed element's source once a decoded buffer plays in its place; the element then sounds natively. */
1055+
/** Drops the routed element's source once a decoded buffer plays in its place. A captured element has no native
1056+
* output, so left unconnected it is silent; WebKit sounds it through the destination even while muted. */
10561057
releaseRouted(el: HTMLMediaElement): void {
10571058
const routed = this._activeSources.find((s) => s.el === el && s.sourceKind === "media-element");
10581059
if (!routed) return;
10591060
this._activeSources.splice(this._activeSources.indexOf(routed), 1);
1060-
this.dispose(routed);
1061+
this.dispose(routed, false);
10611062
this._handedOver.add(el);
10621063
}
10631064

0 commit comments

Comments
 (0)