[Media3] Add support for queues on media3 sessions#5211
[Media3] Add support for queues on media3 sessions#5211
Conversation
There was a problem hiding this comment.
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
PocketCastsForwardingPlayerto maintain queue items, expose aTimeline, and handle queue-item selection viaseekTo(mediaItemIndex, …). - Observe
UpNextQueuechanges inMediaSessionManagerand push mappedMediaItems into the forwarding player + notify Media3 library children changes. - Allow controllers to request timeline info by adding
COMMAND_GET_TIMELINEto 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. |
|
Version |
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.
2423ef8 to
30b4ba9
Compare
|
@geekygecko made some changes in 46779cf - could you please try again? |
|
@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.
The value of |
|
thanks @geekygecko Screen_recording_20260423_114322.mp4Unfortunately 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... |


Description
With
media3_sessionflag 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
Checklist
./gradlew spotlessApplyto automatically apply formatting/linting)modules/services/localization/src/main/res/values/strings.xml