Unexpected calls of `onStartCommand` of `MediaSessionService`
@marcbaechinger is already working on this.
Since Jan 12, 2026.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
Version
Media3 1.9.0
More version details
Hello,
I am encountering a situation regarding ExoPlayer and MediaSessionService. In my app, I use a MediaSessionService to hold the player and expose the controller.
I recently override onStartCommand() (which I don't typically use for logic) to add a one log statement and I noticed the following behavior:
At the start of video initialization, I see several repetitive logs.
During playback, the log triggers approximately every 5 seconds.
The stream itself is working perfectly—clear audio and video with no interruptions/restarts. I have verified that I do not have any loops in my code re-triggering the player, and onGetSession() consistently returns the same session instance.
Going PIP then closing (X - PIP option) as long as media3 notification stays, loops comming. After swipe-closing media3 notification, loops stops
I added a stack trace using RuntimeException("Stack Trace").stackTraceToString() inside onStartCommand().
The Logcat output shows the call coming from the system:
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5752)
at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2728)
...
at android.app.ActivityThread.main(ActivityThread.java:9634)
It appears to be a system-level loop. Some AI-assisted research, suggested this might be normal—specifically a "heartbeat" to keep the player alive or update the Media3 notification.
I don't have any startService() or startForegroundService(). I just use:
fun getFutureController(nContext: Context, nListener: MediaController.Listener): ListenableFuture {
return MediaController.Builder(nContext, SessionToken(nContext, ComponentName(nContext,PlayerService::class.java))).setListener(nListener).buildAsync()
}
to connect to the service
Is this behavior normal? Can anyone confirm if onStartCommand is expected to fire repeatedly like this?
Thanks
Devices that reproduce the issue
Samsung S21
Pixel 7
Devices that do not reproduce the issue
No response
Reproducible in the demo app?
Not tested
Reproduction steps
Starting a video streaming player
Expected result
I expected a few repetitive logs not loop at 5 sec
Actual result
one log in loop at 5 sec
Media
Internal streaming; I can not provide
Bug Report
- You will email the zip file produced by
adb bugreportto android-media-github@google.com after filing this issue.
Contributor 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.
Assessment
This issue has not been assessed yet.