fix(core): apply playbackRate to all media duration resolution sites (#1288)

Extract readElementPlaybackRate() to eliminate clamping duplication across
media.ts, init.ts, startResolver.ts, and timeline.ts. Apply the rate
division to the two remaining sites that were missed:

- startResolver.ts: visibility loop used raw source duration, hiding
  slowed-down videos mid-playback when no data-duration was set
- timeline.ts: resolveMediaElementDurationSeconds underreported the end
  window sent to the renderer, affecting preview parity

Also adds direct tests for readElementPlaybackRate().
This commit is contained in:
Miguel Ángel
2026-06-08 21:29:04 -04:00
committed by GitHub
parent 48711ab135
commit 908b455e5e
5 changed files with 45 additions and 15 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
import type { RuntimeTimelineLike } from "./types";
import { swallow } from "./diagnostics";
import { readElementPlaybackRate } from "./media";
const AUTHORED_DURATION_ATTR = "data-hf-authored-duration";
const AUTHORED_END_ATTR = "data-hf-authored-end";
@@ -106,7 +107,7 @@ export function createRuntimeStartTimeResolver(params: {
parseNumeric(element.getAttribute("data-media-start")) ??
0;
if (Number.isFinite(element.duration) && element.duration > playbackStart) {
resolved = element.duration - playbackStart;
resolved = (element.duration - playbackStart) / readElementPlaybackRate(element);
}
}
if (resolved == null || resolved <= 0) {