You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix lost pause/resume state after a silent playback restart - #96
Kodi can restart playback without announcing it (for example, when Player.updateInfoTag reloads the current item), leaving the session with a stale paused flag.
As a result, a start action may be skipped or sent while playback is paused, causing the reported progress to remain at the beginning after a pause and seek.
Solution
Update tick() to compare the player's actual pause state with the session's recorded state.
Require two consecutive mismatches before applying a correction, avoiding transient state changes.
Apply the corresponding paused or resumed event through the existing event handler.
Read the player's pause state only once per tick.
This keeps the session's pause state synchronized with the player without duplicating the existing pause/resume handling logic.
Summary by CodeRabbit
Bug Fixes
Pause and resume events now better reflect the player’s actual state when it differs from the state recorded for the current session. Brief discrepancies are checked across consecutive updates before the session state is corrected, helping avoid changes based on a single inconsistent update.
No actionable comments were generated in the recent review.
Walkthrough
The scrobbler now checks the player’s paused state against the session state after each valid sample for a non-ignored session. After two consecutive mismatches, it routes a pause or resume event through on_event.
Changes: Pause-state correction
Layer / File(s)
Summary
Track and correct pause state resources/lib/scrobbler.py
Session initializes a mismatch counter. Scrobbler.tick resets it when states match and routes a pause or resume event after two consecutive mismatches.
SIMKL/script.simkl#95: PR #95 changes the resumed handler used by this change to route a detected resume through the existing handler.
Suggested reviewers:ekleop
Merge Risk: Minimal · up to a5461
This change realigns the recorded pause state with Kodi's actual state after a silent playback restart. No actionable merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: fixing pause/resume state that gets lost after a silent playback restart. The raw summary describes a mismatch check in Scrobbler.tick that corrects the session pause …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: fixing pause/resume state that gets lost after a silent playback restart. The raw summary describes a mismatch check in Scrobbler.tick that corrects the session pause state after two consecutive mismatches, which matches the title. The title is specific and concise, and it does not describe anything absent from the changeset.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 83beb18f-bb40-480f-ba33-4d5be2bbbe0d
Commits
Reviewing files that changed from the base of the PR and between 358fa8f and a54611b.
Files selected for processing: 1
resources/lib/scrobbler.py
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
Stop while paused. Kodi reports "not paused" at once, but onPlayBackStopped arrives only after the bookmark is saved. On slow storage that is more than two loop turns, so a start goes to Simkl right before the stop.
Next item while paused. The new item is unpaused at once, its onAVStarted comes seconds later. Meanwhile the old session sends a start for the old item.
Please move the comparison into the once-a-second sample block and run it only when _sample() returned a sample. _sample() already rejects both cases, and it is one read a second instead of four. The two-mismatch rule can stay.
Stop while paused. Kodi reports "not paused" at once, but onPlayBackStopped arrives only after the bookmark is saved. On slow storage that is more than two loop turns, so a start goes to Simkl right before the stop.
Next item while paused. The new item is unpaused at once, its onAVStarted comes seconds later. Meanwhile the old session sends a start for the old item.
Please move the comparison into the once-a-second sample block and run it only when _sample() returned a sample. _sample() already rejects both cases, and it is one read a second instead of four. The two-mismatch rule can stay.
Done. I moved the comparison into the once-a-second sample block and it now runs only when _sample() returned a sample, so a stop or a switch to the next item no longer reaches it. is_paused() is read once per sample instead of several times per tick. The two-mismatch rule is kept.
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
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.
Description
Kodi can restart playback without announcing it (for example, when
Player.updateInfoTagreloads the current item), leaving the session with a stalepausedflag.As a result, a
startaction may be skipped or sent while playback is paused, causing the reported progress to remain at the beginning after a pause and seek.Solution
Update
tick()to compare the player's actual pause state with the session's recorded state.pausedorresumedevent through the existing event handler.This keeps the session's pause state synchronized with the player without duplicating the existing pause/resume handling logic.
Summary by CodeRabbit