Skip to content

[Media3] Add support for queues on media3 sessions#5211

Open
sztomek wants to merge 5 commits intomainfrom
fix/wearos-up-next
Open

[Media3] Add support for queues on media3 sessions#5211
sztomek wants to merge 5 commits intomainfrom
fix/wearos-up-next

Conversation

@sztomek
Copy link
Copy Markdown
Contributor

@sztomek sztomek commented Apr 10, 2026

Description

With media3_session flag enabled we didn't support up next queue. This PR addresses that.

Fixes PCDROID-533 https://linear.app/a8c/issue/PCDROID-533/media3-wearos-media-session-up-next-button-disabled

Testing Instructions

  1. Install wear app with FF ON
  2. Put together a queue
  3. Start playing an episode
  4. Start an excercise on your watch
  5. Swipe right to see the media session
  6. Verify up next button works

Checklist

  • If this is a user-facing change, I have added an entry in CHANGELOG.md
  • Ensure the linter passes (./gradlew spotlessApply to automatically apply formatting/linting)
  • I have considered whether it makes sense to add tests for my changes
  • All strings that need to be localized are in modules/services/localization/src/main/res/values/strings.xml
  • Any jetpack compose components I added or changed are covered by compose previews
  • I have updated (or requested that someone edit) the spreadsheet to reflect any new or changed analytics.

@sztomek sztomek added this to the 8.10 milestone Apr 10, 2026
@sztomek sztomek added the [Type] Bug Not functioning as intended. label Apr 10, 2026
@sztomek sztomek requested a review from a team as a code owner April 10, 2026 20:35
@sztomek sztomek added the [Area] Wear OS watch app label Apr 10, 2026
@sztomek sztomek removed the request for review from a team April 10, 2026 20:35
@sztomek sztomek requested review from Copilot and geekygecko April 10, 2026 20:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Media3 “Up Next” queue support by exposing a queue-backed Timeline from the session player and wiring Up Next queue updates into the Media3 session so external controllers (e.g., Wear OS media session UI) can browse/select queued episodes.

Changes:

  • Extend PocketCastsForwardingPlayer to maintain queue items, expose a Timeline, and handle queue-item selection via seekTo(mediaItemIndex, …).
  • Observe UpNextQueue changes in MediaSessionManager and push mapped MediaItems into the forwarding player + notify Media3 library children changes.
  • Allow controllers to request timeline info by adding COMMAND_GET_TIMELINE to Media3 connection commands.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/PocketCastsForwardingPlayer.kt Adds queue state + timeline exposure and queue-item seeking support for Media3 controllers.
modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/MediaSessionManager.kt Wires Up Next queue updates into the Media3 session/player and handles queue-item selection.
modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/Media3SessionCallback.kt Extends granted player commands to include timeline access.

Copy link
Copy Markdown
Member

@geekygecko geekygecko left a comment

Choose a reason for hiding this comment

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

I could be doing something wrong but the Up Next doesn't seem to be enabled for me.
Image

I don't think the Media3 code sets the mediaSession.setQueue so that isn't showing as enabled but does with the legacy player.
Image

@wpmobilebot wpmobilebot modified the milestones: 8.10, 8.11 Apr 14, 2026
@wpmobilebot
Copy link
Copy Markdown
Collaborator

Version 8.10 has now entered code-freeze, so the milestone of this PR has been updated to 8.11.

sztomek added 3 commits April 16, 2026 17:33
Addresses PR #5211 review comments so Media3's legacy MediaSessionCompat
bridge correctly populates setQueue for external controllers (Wear OS):

- getCurrentMediaItemIndex() returns C.INDEX_UNSET when the timeline is
  empty instead of always 0. Without this the legacy bridge can't set a
  valid active queue item id and Wear disables the Up Next affordance.
- updateMetadata, updateQueue and clearMetadata now notify listeners of
  EVENT_TIMELINE_CHANGED. Changing the current episode rewrites the first
  window of the timeline, so the bridge must know to rebuild setQueue.
- seekTo(mediaItemIndex, positionMs) falls back to super.seekTo(...) when
  onSeekToQueueItem is null (e.g. cast install path) or the index is
  outside the queue range, instead of silently no-oping.
- notifyChildrenChanged uses items.size instead of Int.MAX_VALUE so
  Media3 controllers don't try to page an absurd range.
- De-duplicate podcast lookups by uuid when building the queue to avoid
  N+1 DB hits for queues containing multiple episodes of the same show.
Covers behaviour introduced in PR #5211 plus the fixes from the previous
commit: getCurrentMediaItemIndex returning INDEX_UNSET / 0, timeline
composition from current item + queue, onTimelineChanged and onEvents
(EVENT_TIMELINE_CHANGED) firing from updateQueue / updateMetadata /
clearMetadata, seekTo queue routing with fallback when the callback is
null or the index is out of range, and swapPlayer preserving queue
state and onSeekToQueueItem.
@sztomek sztomek force-pushed the fix/wearos-up-next branch from 2423ef8 to 30b4ba9 Compare April 16, 2026 15:39
Copilot AI review requested due to automatic review settings April 22, 2026 10:31
@sztomek
Copy link
Copy Markdown
Contributor Author

sztomek commented Apr 22, 2026

@geekygecko made some changes in 46779cf - could you please try again?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

@sztomek sztomek requested a review from geekygecko April 22, 2026 10:55
@geekygecko
Copy link
Copy Markdown
Member

@sztomek it still doesn't seem to be working for me. I had a quick look and couldn't figure out a fix.

I did experience one crash which might be related to this code change.

androidx/media3/session/PlayerWrapper.java

  public PositionInfo createPositionInfo() {
    boolean canAccessCurrentMediaItem = isCommandAvailable(COMMAND_GET_CURRENT_MEDIA_ITEM);
    boolean canAccessTimeline = isCommandAvailable(COMMAND_GET_TIMELINE);
    int currentMediaItemIndex = canAccessTimeline ? getCurrentMediaItemIndex() : 0;
    checkState(currentMediaItemIndex >= 0);

getCurrentMediaItemIndex has to return a value greater than or equal to 0. Our PocketCastsForwardingPlayer implementation has the following:

    override fun getCurrentMediaItemIndex(): Int {
        // Per Player contract, return C.INDEX_UNSET when there's no current window.
        // Returning 0 would make controllers think the first queue item is currently
        // playing when playback is idle, and prevents the legacy bridge from setting
        // a valid active queue item id (breaks Wear OS Up Next affordance).
        return if (currentMediaItem == MediaItem.EMPTY) C.INDEX_UNSET else 0
    }

The value of INDEX_UNSET = -1;. I think the value of our current item would always be 0.

@sztomek
Copy link
Copy Markdown
Contributor Author

sztomek commented Apr 23, 2026

thanks @geekygecko
i've pushed a new commit that addresses the issue you've flagged. i was also able to verify on AUTOMOTIVE that the up next queue works.

Screen_recording_20260423_114322.mp4

Unfortunately i'm not seeing the same UI on my Galaxy Watch 4 during an excercise that you do and I didn't find any ways to bring it up on a watch emulator either...
could you please check again? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Area] Up Next [Area] Wear OS watch app [Type] Bug Not functioning as intended.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants