mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 22:28:45 +00:00
On Safari/WebKit, video.currentTime (the playback clock) runs ahead of the frame actually presented on screen at playback start, and the first requestVideoFrameCallback arrives only after a delay. useFramePlayer drove the playhead from currentTime immediately on play, racing it forward, then snapped it backward when the first rVFC reported the true (lower) presented frame. Fix 1 (play-start rewind): reset the per-session VFC state on each play and only use the currentTime/RAF path when rVFC is unsupported, or has delivered a frame this session and then stalled (e.g. video track ended while audio continues), or never delivered within a safety grace. The playhead now follows the actually presented frame instead of the leading playback clock. Fix 2 (pause snap): on pause, prefer the last presented mediaTime when rVFC is fresh so the playhead locks to the frame the user is looking at, instead of jumping forward to the leading currentTime. Falls back to currentTime when rVFC is stale/unsupported. Add a deterministic useFramePlayer hook unit test (happy-dom) that simulates Safari's leading currentTime and lagging mediaTime; it asserts the playhead is monotonic on play and locks to the presented frame on pause (both fail on the old logic), and that the end-of-track currentTime fallback still works.