Skip to content

Add Media3 session and library session callbacks#5144

Merged
sztomek merged 11 commits intomainfrom
media3/04-session-callbacks
Apr 8, 2026
Merged

Add Media3 session and library session callbacks#5144
sztomek merged 11 commits intomainfrom
media3/04-session-callbacks

Conversation

@sztomek
Copy link
Copy Markdown
Contributor

@sztomek sztomek commented Mar 18, 2026

Description

This PR is the 4th step of media3 migration.
This adds key components vital to the session ecosystem.
Media3SessionCallback takes care of connecting and disconnecting to the service, setting capabilities and forwarding custom commands to the underlyign player.
Media3LibrarySessionCallback provides browse and search functionality, and delegates session-related calls to the session callback.

Testing Instructions

Just review the code pls

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 Mar 18, 2026
@sztomek sztomek requested a review from a team as a code owner March 18, 2026 10:02
@sztomek sztomek requested review from Copilot and geekygecko and removed request for a team March 18, 2026 10:02
@sztomek sztomek added do not merge [Type] Enhancement Improve an existing feature. [Area] Playback Episode playback issue labels Mar 18, 2026
@dangermattic
Copy link
Copy Markdown
Collaborator

dangermattic commented Mar 18, 2026

1 Warning
⚠️ This PR is larger than 500 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

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

This PR advances the Media3 migration by introducing Media3 session callback implementations for session connection/custom commands and for library browsing/search, along with unit tests validating key behaviors.

Changes:

  • Added Media3SessionCallback to handle MediaSession connection capabilities, custom commands, rating, media-button events, and play-from-search/mediaId behavior.
  • Added Media3LibrarySessionCallback to provide browse tree + search APIs and delegate session-level operations to Media3SessionCallback.
  • Added Robolectric tests for both callbacks, and exposed legacy custom-action constants for reuse in the new callbacks/tests.

Reviewed changes

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

Show a summary per file
File Description
modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/Media3SessionCallback.kt New Media3 MediaSession.Callback implementing connection commands, custom commands, media button handling, etc.
modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/Media3LibrarySessionCallback.kt New Media3 MediaLibrarySession.Callback for browse/search and delegation to the session callback.
modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/MediaSessionManager.kt Makes app custom-action constants internal so they can be reused by Media3 code/tests.
modules/services/repositories/src/test/java/au/com/shiftyjelly/pocketcasts/repositories/playback/Media3SessionCallbackTest.kt Adds tests for connection commands, custom commands, rating, and media-button behavior.
modules/services/repositories/src/test/java/au/com/shiftyjelly/pocketcasts/repositories/playback/Media3LibrarySessionCallbackTest.kt Adds tests for library root/children/search, connection validation, and playback resumption.

You can also share your feedback on Copilot code review. Take the survey.

import androidx.media3.session.MediaLibraryService
import androidx.media3.session.MediaSession
import androidx.media3.session.SessionCommand
import au.com.shiftyjelly.pocketcasts.models.entity.BaseEpisode
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed — removed unused BaseEpisode import.

@sztomek sztomek modified the milestones: 8.10, 8.9 Mar 20, 2026
@sztomek sztomek force-pushed the media3/03-browse-tree branch from 6d0e4b8 to 1ad148d Compare March 27, 2026 16:01
@sztomek sztomek force-pushed the media3/04-session-callbacks branch from d85dfab to 4841ed3 Compare March 27, 2026 16:03
@wpmobilebot wpmobilebot modified the milestones: 8.9, 8.10 Mar 30, 2026
@wpmobilebot
Copy link
Copy Markdown
Collaborator

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

@sztomek sztomek force-pushed the media3/03-browse-tree branch from 1ad148d to 3ef0f55 Compare March 31, 2026 15:48
@sztomek sztomek force-pushed the media3/03-browse-tree branch from 3ef0f55 to 952392b Compare March 31, 2026 16:18
Copilot AI review requested due to automatic review settings March 31, 2026 17:21
@sztomek sztomek force-pushed the media3/04-session-callbacks branch from 4841ed3 to 497b54c Compare March 31, 2026 17:21
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 the initial Media3 Session / LibrarySession callback implementations (and accompanying unit tests) as part of the Media3 migration, providing command routing, media-button handling, and browse/search plumbing.

Changes:

  • Introduce Media3SessionCallback to handle connection capabilities, custom commands, rating, play-from-id/search, and media-button events.
  • Introduce Media3LibrarySessionCallback to provide browse/search and delegate session-level behavior to Media3SessionCallback.
  • Add Robolectric tests for both callbacks; expose legacy APP_ACTION_* constants for reuse.

Reviewed changes

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

Show a summary per file
File Description
modules/services/repositories/src/test/java/au/com/shiftyjelly/pocketcasts/repositories/playback/Media3SessionCallbackTest.kt Adds unit coverage for Media3 session connect/custom commands/rating/media-button handling.
modules/services/repositories/src/test/java/au/com/shiftyjelly/pocketcasts/repositories/playback/Media3LibrarySessionCallbackTest.kt Adds unit coverage for library root/children/search, connection validation, and delegation.
modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/MediaSessionManager.kt Makes APP_ACTION_* constants internal so Media3 callbacks/tests can reuse them.
modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/Media3SessionCallback.kt New Media3 MediaSession.Callback implementation.
modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/Media3LibrarySessionCallback.kt New Media3 MediaLibrarySession.Callback implementation with browse/search + delegation.

@sztomek sztomek force-pushed the media3/03-browse-tree branch from 952392b to d19918c Compare April 1, 2026 17:29
- Only set userRating for PodcastEpisode (UserEpisode doesn't support starring)
- Use PLAY_WHEN_READY_CHANGE_REASON_REMOTE for cast state updates

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sztomek sztomek force-pushed the media3/03-browse-tree branch from d19918c to fc7b947 Compare April 1, 2026 20:25
@sztomek sztomek force-pushed the media3/04-session-callbacks branch from f992988 to 376454a Compare April 1, 2026 20:26
Copilot AI review requested due to automatic review settings April 2, 2026 10:56
@sztomek sztomek force-pushed the media3/04-session-callbacks branch from 376454a to 8eceb80 Compare April 2, 2026 10:56
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 1 comment.

sztomek and others added 4 commits April 8, 2026 10:12
- Simplify seekTo overloads (remove redundant if/else)
- Prevent duplicate listeners in internal list
- Treat blank artwork URLs as null
This test references methods (loadSuggestedChildren, loadRecentChildren)
and fields (upNextQueue, podcastManager, episodeManager, playlistManager)
that were extracted from PlaybackService into BrowseTreeProvider.
The same functionality is now covered by BrowseTreeProviderTest.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sztomek sztomek force-pushed the media3/03-browse-tree branch from 6430eb6 to f2c3455 Compare April 8, 2026 08:21
sztomek and others added 4 commits April 8, 2026 10:21
Return SessionError.ERROR_NOT_SUPPORTED instead of RESULT_SUCCESS
when the provided Rating is not a HeartRating.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sztomek sztomek force-pushed the media3/04-session-callbacks branch from 8eceb80 to 9c15b07 Compare April 8, 2026 08:25
Base automatically changed from media3/03-browse-tree to main April 8, 2026 08:59
@sztomek sztomek merged commit 739a03b into main Apr 8, 2026
19 checks passed
@sztomek sztomek deleted the media3/04-session-callbacks branch April 8, 2026 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Area] Playback Episode playback issue [Type] Enhancement Improve an existing feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants