Skip to content

Fixed Playback advanding multiple chapter; Playbar Improvments#144

Merged
rstewa merged 4 commits intorstewa:mainfrom
KeinNiemand:pr/playing-bar-bugfix
Apr 2, 2026
Merged

Fixed Playback advanding multiple chapter; Playbar Improvments#144
rstewa merged 4 commits intorstewa:mainfrom
KeinNiemand:pr/playing-bar-bugfix

Conversation

@KeinNiemand
Copy link
Copy Markdown
Contributor

This PR Fixes a bug that made the player sometimes jump ahead multiple chapter after reaching the end of a file,

Additionally:
I also made some changes to how the playbar function, previously if you held your mouse down and dragged while the audio book was playing the bar would constanly jump between where you want to drag it and where the current playback position, the bar also was unusable on touch screen.

…next

When a media file ended, AudioPlayer_MediaEnded used CurrentChapterIndex + 1
to determine the starting chapter of the next file. Due to a race with the
PositionChanged handler (which fires rapidly near the end of a file and could
leave CurrentChapterIndex in a stale or wrong state), this caused the player
to skip 2-3 chapters past the correct position.

Fix: instead of incrementing the chapter index, explicitly find the first
chapter whose ParentSourceFileIndex matches the next source file.
@rstewa
Copy link
Copy Markdown
Owner

rstewa commented Mar 29, 2026

This is awesome. I just tried it out and it seems to work great. I want to take a little more in depth look in a day or so but unless something changes, I should be able to put this in the next release.

@rstewa rstewa self-assigned this Mar 29, 2026
PositionChanged fires many times per second and was calling SaveAsync on
every tick. Each save creates a new DbContext, queries the full audiobook
with all chapters and source paths, then writes — an expensive operation.
When seeking backward in m4b files (which already requires decoding from
an AAC keyframe), these saves pile up and stall the app for 60+ seconds.

Fix: throttle saves to at most once every 2 seconds in PositionChanged.
This is sufficient for resume bookmarking and eliminates the freeze.
@KeinNiemand
Copy link
Copy Markdown
Contributor Author

Hey, just wanted to flag that I added a third commit to this branch after you started reviewing. While investigating the chapter-skip bug I found an unrelated but significant issue: rewinding in m4b files causes the app to freeze for 60+ seconds.

Root cause: PlaybackSession_PositionChanged was calling SaveAsync() on every tick. Each save creates a new DbContext, queries the full audiobook with all chapters and source paths, then writes, which is a very expensive operation. When seeking backward in m4b (which already requires decoding from an AAC keyframe), these saves pile up and stall the app.

Fix: throttle saves in PositionChanged to at most once every 2 seconds, which is still sufficient for resume bookmarking.

I can split this into a separate PR if you prefer, just let me know.

@KeinNiemand
Copy link
Copy Markdown
Contributor Author

I reverted the above changes since it didn't actually always fix the problem, as far as I can tell the real root cause problem is that windows media player just takes 30s to load my 400mb m4b file, the only real fix would be to swap out windows media player for another library to do playback.

@rstewa
Copy link
Copy Markdown
Owner

rstewa commented Mar 29, 2026

I think this fixes #142

@KeinNiemand
Copy link
Copy Markdown
Contributor Author

I think this fixes #142

It might but I think I have encountered #142 once myself even with this fix once (I'm not 100% I didn't just left it playing for longer then I think I did and can't reproduce it, also I'm on a different single file audio book now).

Advancing multiple chapters at once problem fixed here might be a separate bug from sometimes starting playback mid chapter after advancing.

@rstewa
Copy link
Copy Markdown
Owner

rstewa commented Apr 2, 2026

I think this PR looks good. Gonna merge it.

@rstewa rstewa merged commit 7ebef5e into rstewa:main Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants