MediaSessionService: the platform session keeps every player command and publishes the whole queue until the session is added, e.g. after a sticky restart
Maintainers usually reply within 4 days
@marcbaechinger is already working on this.
Since Oct 26, 2026.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start by tracing MediaSessionService.onCreate(), onStartCommand() and addSession(), then follow how MediaNotificationManager connects its controller and how the platform session receives player commands. Reproduce the sticky restart and inspect dumpsys media_session; done means the platform session respects the notification controller's command restriction from startup and resumed playback runs with the media notification and foreground service.
Written by the indexing model from the issue text.
Description
Version
Media3 pre-release (alpha, beta or RC not in this list)
More version details
Media3 1.12.0-alpha01. Also reproduced with 1.11.1.
Devices that reproduce the issue
- Android emulator, API 30 (Android 11). Not tried on other devices; nothing in the path described below depends on the API level.
Devices that do not reproduce the issue
No response
Reproducible in the demo app?
Not tested
Reproduction steps
The documented pattern builds the MediaSession in MediaSessionService.onCreate() and returns it from onGetSession(). The platform session takes its commands from the media notification controller, so removing Player.COMMAND_GET_TIMELINE from that controller in MediaSession.Callback.onConnect keeps the queue out of the platform session (1.2.0 release notes).
That restriction only takes effect once MediaSessionService.addSession() has run, because only then does MediaNotificationManager connect the notification controller. Until then the legacy stub keeps DEFAULT_PLAYER_COMMANDS. When the system restarts a sticky service after its process was killed while playing, onStartCommand(null) returns START_STICKY without adding the session, while the platform session is already active. The next headset key then reaches the platform session directly, onPlaybackResumption restores the queue, and the platform session publishes it.
- A
MediaSessionServicethat builds its session inonCreate, removesCOMMAND_GET_TIMELINEfrom the media notification controller inonConnect, and restores a queue inonPlaybackResumption. - Play, then
adb shell kill -9 <pid>while playing. The system schedules a restart of the crashed service. - Once it has restarted,
adb shell input keyevent KEYCODE_MEDIA_PLAY. adb shell dumpsys media_session
Expected result
The platform session follows the media notification controller's commands from the start, so it never holds the queue, and playback resumed this way runs in the foreground under the media notification.
Calling addSession(session) in onCreate, right after building the session, works around it: https://github.com/LordDetson/piplayer/commit/f502ab7
Actual result
- The platform session publishes the whole queue (
dumpsys media_sessionshows its size) until any Media3 controller connects; opening the app's activity clears it. With a large queue that is every item on every timeline change. - Playback runs without the media notification and without the foreground service.
- On Android 11 the queue appearing and disappearing again also hits a race in the Bluetooth AVRCP service:
MediaPlayerWrapper.isMetadataSyncedcallsgetQueue()twice, andcom.android.bluetoothcrashed once with aNullPointerExceptionin our runs (fixed in Android 12 by "AVRCP: Cache queue in isMetadataSynced").
Related: #459 (START_STICKY restarts).
Media
Not applicable. An instrumented test that reproduces the state without killing the process (a binding that Media3 does not serve creates the service without addSession): https://github.com/LordDetson/piplayer/blob/main/app/src/androidTest/kotlin/io/github/lorddetson/piplayer/playback/PlatformQueueTest.kt
Bug Report
- You will email the zip file produced by
adb bugreportto [email protected] after filing this issue.
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 998
- Avg merge
- 6d 8h
- Merged PRs (30d)
- 2
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from androidx/media
-
Waive ads when seek/start at the beginningPossibly taken @microkatz claimed this today. Openenhancement
androidx/media#3496 · 2 comments · 1 assignee ·
Maintainers usually reply within 4 days
-
Since 1.9.0, skip buttons in SLOT_BACK / SLOT_FORWARD reach legacy controllers as custom actionsPossibly taken @marcbaechinger claimed this today. Openbug
androidx/media#3495 · 1 comment · 1 assignee ·
Maintainers usually reply within 4 days
-
Allow configuring asset-list prefetch timing per HLS interstitialPossibly taken @marcbaechinger claimed this today. Openenhancement needs triage
androidx/media#3494 · 1 assignee ·
Maintainers usually reply within 4 days
-
Offloaded audio left paused keeps AudioFlinger's AudioOffload wake lock forever, device never suspendsPossibly taken @microkatz claimed this today. Open
androidx/media#3493 · 1 assignee ·
Maintainers usually reply within 4 days
-
Allow opting into frame-index seeking for MP3s without reliable seek metadataPossibly taken @icbaker claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
androidx/media#3492 · 1 assignee ·
Maintainers usually reply within 4 days
Similar issues
-
priority: medium Review effort [1-5]: 3 status: needs-triage type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
carlos-emr/carlos#5431 ·
Maintainers usually reply within 1 day
-
Integration tests: jetty:run fails with WELD-001408 for CountryJpaServicePossibly taken @viniciusmachak claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
primefaces/primefaces#15431 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
OpenAPITools/openapi-generator#25454 ·
Maintainers usually reply within 1 day
-
Component - Build
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100