Skip to content

Commit 1be5dee

Browse files
committed
fix(player): a clip that replaces another on the same file keeps its sound
1 parent dd0987d commit 1be5dee

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

‎packages/player/src/parent-media.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,19 @@ describe("ParentMediaManager following its clips", () => {
310310
expect(files(mgr)).toEqual(["https://example.test/a.mov"]);
311311
});
312312

313+
it("gives a clip that replaces another on the same file its own proxy", async () => {
314+
const mgr = makeManager();
315+
const old = adoptedClip(mgr, "https://example.test/a.mov");
316+
const replacement = document.createElement("video");
317+
replacement.setAttribute("src", "https://example.test/a.mov");
318+
replacement.setAttribute("data-start", "0");
319+
replacement.preload = "auto";
320+
document.body.replaceChild(replacement, old);
321+
await flushObserver();
322+
323+
expect(mgr.entries.map((m) => m.source)).toEqual([replacement]);
324+
});
325+
313326
it("drops the proxy of a re-pointed clip when the clip leaves", async () => {
314327
const mgr = makeManager();
315328
const clip = adoptedClip(mgr, "https://example.test/clip.mov");

‎packages/player/src/parent-media.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,12 @@ export class ParentMediaManager {
413413
}
414414

415415
/** One proxy per file: a second clip on the same file is heard through the first one's proxy.
416-
* A proxy's file is its clip's current one; it may still be loading the clip's earlier file. */
416+
* A proxy's file is its clip's current one (a clip that left the page owns none). */
417417
private _urlTaken(src: string, except?: ProxyEntry): boolean {
418-
return this._entries.some(
419-
(m) =>
420-
m !== except && ((m.source && this._resolveIframeMediaSrc(m.source)) || m.el.src) === src,
421-
);
418+
return this._entries.some((m) => {
419+
if (m === except || (m.source && !m.source.isConnected)) return false;
420+
return ((m.source && this._resolveIframeMediaSrc(m.source)) || m.el.src) === src;
421+
});
422422
}
423423

424424
private _repointToSource(entry: ProxyEntry): boolean {

0 commit comments

Comments
 (0)