fix(core): a muted video's picture no longer waits on its own audio track at a cut (#7412)

* fix(core): a muted video's picture no longer waits on its own audio track at a cut

A muted video takes its clock from its audio track in Safari; a late start of that track stalls the picture after the cut. The runtime now switches the track off.

* test(core): a video muted by script and unmuted later keeps its audio track

* fix(core): type the audio track loop so it passes the strict index check
This commit is contained in:
Miguel Ángel
2026-11-08 18:48:55 +00:00
committed by GitHub
parent eb16510a10
commit fa2e63515f
2 changed files with 55 additions and 0 deletions
+47
View File
@@ -1624,6 +1624,53 @@ describe("syncRuntimeMedia", () => {
expect(onElementVolume).toHaveBeenLastCalledWith(clip.el, 0.5, 1, 0.8);
});
describe("a muted video's own audio track", () => {
// A muted video still takes its clock from its audio track; a late track start stalls the picture after a cut.
const withTracks = (el: HTMLMediaElement, tracks: Array<{ enabled: boolean }>) =>
Object.defineProperty(el, "audioTracks", { value: tracks, configurable: true });
const tick = (clip: RuntimeMediaClip) =>
syncRuntimeMedia({ clips: [clip], timeSeconds: 5, playing: true, playbackRate: 1 });
it("is switched off for a video the author muted", () => {
const clip = createMockClip({ start: 0, end: 10 });
clip.el.setAttribute("muted", "");
const tracks = [{ enabled: true }];
withTracks(clip.el, tracks);
tick(clip);
expect(tracks[0].enabled).toBe(false);
});
it("stays on for a video that can sound", () => {
const clip = createMockClip({ start: 0, end: 10 });
const tracks = [{ enabled: true }];
withTracks(clip.el, tracks);
tick(clip);
expect(tracks[0].enabled).toBe(true);
});
it("stays on for a video that is muted by script and unmuted later", () => {
const clip = createMockClip({ start: 0, end: 10 });
const tracks = [{ enabled: true }];
withTracks(clip.el, tracks);
clip.el.muted = true;
tick(clip);
clip.el.muted = false;
tick(clip);
expect(tracks[0].enabled).toBe(true);
});
it("is switched off when the browser lists it after the first tick", () => {
const clip = createMockClip({ start: 0, end: 10 });
clip.el.setAttribute("muted", "");
const tracks: Array<{ enabled: boolean }> = [];
withTracks(clip.el, tracks);
tick(clip);
tracks.push({ enabled: true });
tick(clip);
expect(tracks[0].enabled).toBe(false);
});
});
describe("per-element mute (Web Audio ownership)", () => {
it("mutes a clip whose element the transport owns", () => {
const clip = createMockClip({ start: 0, end: 10 });
+8
View File
@@ -473,6 +473,13 @@ function learnVideoStartLatency(el: HTMLMediaElement, time: number, offset: numb
videoStartLatency = Math.min(0.1, Math.max(0, averaged));
}
/** A muted video takes its clock from its audio track, whose late start stalls the picture after a cut. */
function dropSilentAudioTrack(el: HTMLMediaElement): void {
if (el.tagName !== "VIDEO" || !el.defaultMuted) return;
const tracks = (el as { audioTracks?: ArrayLike<{ enabled: boolean }> }).audioTracks;
for (const track of Array.from(tracks ?? [])) track.enabled = false;
}
// fallow-ignore-next-line complexity
export function syncRuntimeMedia(params: {
clips: RuntimeMediaClip[];
@@ -534,6 +541,7 @@ export function syncRuntimeMedia(params: {
for (const clip of params.clips) {
const { el } = clip;
if (!el.isConnected) continue;
dropSilentAudioTrack(el);
const clipRate = clip.rate ?? clip.playbackRate;
const origin = clip.origin ?? clip.start;
const isNonLoopVideo = el.tagName === "VIDEO" && !clip.loop;