Start recording when playback starts, not only when the track changes - #34
Merged
Conversation
Pressing record with Spotify paused and then pressing play recorded nothing. The level meter moved, the counter ran and the page named the song, but no file appeared until the user pressed stop and start again. Being played is half of what makes a track recordable, and the admission check ran only on a track change. Track equality ignores the play state on purpose, so that a pause mid-song does not read as a new song — which means a track that starts playing raises no track change at all. The session had already passed it over once as not recordable, and went on waiting for something that had already happened. The predecessor never met this: it blocked on Spotify producing audio before it began watching. Offstream starts listening the moment record is pressed, which is the better behaviour and is worth keeping. The admission check moves into Consider, called from the track-changed handler as before and now from the play-state handler too. The resume path is narrower than the track-changed one, deliberately: - only when nothing is being recorded, so a pause mid-song leaves the running recorder alone rather than starting a second one on top of it; - not once the recording timer has elapsed, since the session is winding down and "recording timer elapsed" would be a lie about a resume; - only for the track already showing. One poll can see both a new song and a change of play state — starting with Spotify already playing is exactly that — and the track change is raised straight after, with the stop-the-outgoing- recorder handling this path does not have. Admitting from both would start a recorder for the other to tear down, and discard the fragment as too short. The play-state event now carries the track it observed. The poller does not store the observation until the poll finishes, so a handler reading its current track gets the previous one, whose play state is the one that just stopped being true. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
revtex
force-pushed
the
fix/record-when-playback-starts
branch
from
August 15, 2026 02:53
d07ded0 to
cc21036
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #33 — review that one first. The diff against
mainwill collapse to just this change once #33 merges.What was wrong
Press record while Spotify is paused, then press play: the meter moves, the counter runs, the page names the song, and nothing is ever recorded until you stop and start again.
Being played is half of what makes a track recordable (
Track.IsNormalPlaying, viaRecordingPolicy.IsTypeAllowed), and that check ran only inOnTrackChanged.Track.Equalsignores the play state on purpose — so that a pause mid-song does not read as a new song — which means a track that starts playing raises no track change at all. It raisesPlayStateChanged, which only reported a stage.So the session passed the track over once as not recordable and then waited for a change that had already happened:
The predecessor never met this —
Watcher.SetSpotifyAudioSessionAndWaitToStart()blocks on Spotify producing audio before it begins watching. Offstream starts listening the moment record is pressed, which is the better behaviour and worth keeping.What changed
The admission check moves into
Consider(track), called fromOnTrackChangedas before and now fromOnPlayStateChangedtoo. The resume path is deliberately narrower than the track-changed one:TrackChangedis raised straight after, carrying the stop-the-outgoing-recorder handling this path does not have. Admitting from both would start a recorder only for the other to tear it down, discarding the fragment as too short.PlayStateChangedEventArgsnow carries the track it observed.PollOnceAsyncdoes not store the observation until the poll finishes, so a handler readingpoller.CurrentTrackgets the previous one — whose play state is precisely the one that just stopped being true.Testing
Session_WhenPlaybackStartsOnTheTrackAlreadyShowing_RecordsIt— the reported sequence. Confirmed failing against the unfixed session.Session_WhenPlaybackIsAlreadyUnderWay_StartsOneRecorder— guards the third bullet above. Passes before and after, by design: it is there to catch the regression this fix could have introduced, not the bug it fixes.dotnet format --verify-no-changesclean.🤖 Generated with Claude Code