Skip to content

fix: Make "Play Next" actually play next under shuffle (#329)#910

Merged
eddyizm merged 3 commits into
developmentfrom
bug/play-next-inconsistent
Jul 24, 2026
Merged

fix: Make "Play Next" actually play next under shuffle (#329)#910
eddyizm merged 3 commits into
developmentfrom
bug/play-next-inconsistent

Conversation

@eddyizm

@eddyizm eddyizm commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Summary

Applied the "Play Next under shuffle" fix (from @herrerad85 commit #c55440e3d9d55988995cdce759470d45962ac6e7 ) across 4 files, adapted to the current repo (which was in the patch's exact "before" state) resolves #329 :

  • Constants.kt — added CUSTOM_COMMAND_PLAY_NEXT + PLAY_NEXT_INSERT_POS / PLAY_NEXT_COUNT / PLAY_NEXT_TARGET_COUNT.
  • BaseSessionCallback.kt — registered the custom command in onConnect and handled it in onCustomCommand (calls service.requestPlayNextFixup(...)).
  • MediaManager.java — added 4 imports; both enqueue overloads now insert at current + 1 on the timeline and call the new insertPlayNext() helper, which sends the fixup command to the service and does the timeline addMediaItems.
  • BaseMediaService.kt — added requestPlayNextFixup/tryApplyPlayNextFixup (rebuilds DefaultShuffleOrder so the inserted items play immediately after the current track; safe no-op when shuffle off or counts mismatch) and a tryApplyPlayNextFixup() call in onTimelineChanged.
    Root cause it fixes: under shuffle, getNextMediaItemIndex() is shuffle-order-dependent and ExoPlayer randomizes a newly-inserted item's shuffle position — so "play next" landed at a random spot. Now the item is deterministically inserted at current+1 on the timeline and re-spliced into shuffle position current+1.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a3332f62-6414-413c-9dcb-61fb45db2d23

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Changes

Play-next shuffle workflow

Layer / File(s) Summary
Play-next insertion protocol
app/src/main/java/com/cappielloantonio/tempo/util/Constants.kt, app/src/main/java/com/cappielloantonio/tempo/service/MediaManager.java
Defines command parameters and routes single- and multi-item “play next” enqueue operations through timeline insertion with metadata.
Session command forwarding
app/src/main/java/com/cappielloantonio/tempo/service/BaseSessionCallback.kt
Advertises the play-next command to applicable controllers and forwards its arguments to the media service.
Deferred shuffle-order correction
app/src/main/java/com/cappielloantonio/tempo/service/BaseMediaService.kt
Stores pending fixup data, waits for timeline visibility, and rebuilds shuffle order by placing inserted items after the current track when state is valid.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • eddyizm/tempus#866: Modifies BaseMediaService.onTimelineChanged for another timeline-driven queue operation.

Suggested reviewers: mafo-28, herrerad85

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing Play Next behavior when shuffle is enabled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bug/play-next-inconsistent

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/src/main/java/com/cappielloantonio/tempo/service/BaseMediaService.kt`:
- Around line 179-223: Replace the single pending-request fields used by
requestPlayNextFixup and tryApplyPlayNextFixup with a FIFO queue of (insertPos,
count, target) requests. Enqueue every valid request, then have
tryApplyPlayNextFixup inspect the queue head and retain it until its target item
count is visible and the fixup is successfully handled; remove only the
processed or explicitly invalidated request, then continue applying any newly
eligible queued requests so overlapping Play Next operations are preserved.

In `@app/src/main/java/com/cappielloantonio/tempo/service/MediaManager.java`:
- Around line 357-380: Update insertPlayNext to retain the ListenableFuture
returned by browser.sendCustomCommand and attach failure handling that logs
rejected or failed fixup commands, including the throwable details. Keep the
existing timeline insertion and successful-command behavior unchanged, and use
the class’s established logging mechanism.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 86c48f3b-8ee5-4cba-9e9a-8a1e7998ac04

📥 Commits

Reviewing files that changed from the base of the PR and between 6dcd52e and 8a8a32c.

📒 Files selected for processing (4)
  • app/src/main/java/com/cappielloantonio/tempo/service/BaseMediaService.kt
  • app/src/main/java/com/cappielloantonio/tempo/service/BaseSessionCallback.kt
  • app/src/main/java/com/cappielloantonio/tempo/service/MediaManager.java
  • app/src/main/java/com/cappielloantonio/tempo/util/Constants.kt

Comment thread app/src/main/java/com/cappielloantonio/tempo/service/BaseMediaService.kt Outdated
@eddyizm
eddyizm merged commit f35dfca into development Jul 24, 2026
1 check passed
@eddyizm
eddyizm deleted the bug/play-next-inconsistent branch July 24, 2026 02:39
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.

1 participant