Skip to content

fix(player): join the sound once the window shows again - #35

Merged
houko merged 1 commit into
mainfrom
fix/player-join-sound
Nov 9, 2026
Merged

houko merged 1 commit into
mainfrom
fix/player-join-sound

Conversation

@houko

@houko houko commented Nov 9, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #32, which was merged before this commit was pushed to its branch.

Coming back to the app after its window was hidden still made the picture stop for a moment. On macOS a window coming back reports itself shown a frame or more after the app is active, and VideoPlayer only counts time and starts decoding from then. The picture #32 hands over at activation stood on its first frame through that and then for its whole length again. It then skipped the frames it was late on, and trailed the sound by about 50ms from then on.

  • The handed-over frame lasts 1ms, so VideoPlayer asks for the next one as soon as the window really shows.
  • frameDecoder then gives the frame the sound is in at that moment, for what is left of it (frameDecoder.sound, set by takeBackgroundPicture), so from the first moving frame the picture follows the sound clock.

Screenshots

The real app ran with a fake HOME and a test clip that has a seconds counter. The app was hidden for about 4s and then brought back. The pair shows the first frame after the window appears and the frame 100ms later, at full size. The handover happened at 35.67s, so the first frame is already at 35, and the gradient strip has moved on 100ms later.

After: the first frame after the return is already at 35

Before this change, timing logs from the same scenario show the playhead standing still and then skipping three frames at once: 9.001s → 9.001s → 9.101s → 9.134s. Still images can't show that, so there is no before image.

Verification

Hidden for about 4s, then brought back. Each run was recorded with screencapture, and per-frame change in the moving gradient strip gives the time from the window appearing to the picture moving:

Build Window appears → picture moves
background follow turned off (baseline for any window showing again) 34 / 79 / 50 / 75ms
main (#32) 92 / 125 / 75 / 108 / 67 / 234 / 117 / 108ms, then a skip
this PR 53 / 75 / 75 / 42 / 42 / 50ms

With this PR, 5 of 6 runs had no gap over 60ms in the 2s after the return. One run had gaps of 66–78ms, which steady playback with no switching shows too: two to five per 2s, from the screen recording's timing. Timing logs from a local build show the decoder joining the sound 15–30ms after the handover, as the window shows, on the frame the sound is in, and every frame after it following the sound.

Tests:

  • TestHandedOverPictureJoinsTheSound: with real ffmpeg on a 10fps clip, the held frame lasts 1ms. With the sound at 450ms, the next frame given is the one from 400 to 500ms, lasting 50ms, and the frames after it last their full length.
  • make test, go vet, and the player and volume tests with -race.

On macOS the window reports itself shown a frame or more after the app is back, and VideoPlayer only counts time and starts decoding from then. The picture handed over from the background stood on its first frame through that, for its whole length again, then skipped the frames it was late on and trailed the sound by the time the window took to show (about 50ms). Coming back took about 110ms before the picture moved, against about 60ms for a window showing again with no handover at all.

The handed-over frame now lasts 1ms, so VideoPlayer asks for the next one as soon as the window shows, and frameDecoder then gives the frame the sound is in, for what is left of it. On the real app the picture now moves about 56ms after the window appears, the same as with no handover, and frames follow the sound clock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added area: app The app shell and state in apps/kando bug size/S 10 to 99 changed lines labels Nov 9, 2026
@houko
houko merged commit ddc8016 into main Nov 9, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: app The app shell and state in apps/kando bug size/S 10 to 99 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant