Media3 + IMA: In background, ad audio finishes but AD events don’t complete (no ALL_ADS_COMPLETED) → preroll restarts
@marcbaechinger is already working on this.
Since Sep 24, 2025.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
I’m using Media3 ExoPlayer with MediaLibraryService and IMA client-side preroll.
In foreground, everything is correct: the preroll (10s) plays once, then content (video/audio) starts normally.
The issue happens only in background:
- While the preroll is playing, I send the app to the background.
- The ad audio continues and finishes.
- However, IMA does not emit COMPLETE / ALL_ADS_COMPLETED in background.
- When the ad media ends, content begins for ~1–2s and then the same preroll starts again.
- This can repeat 3–4 times before stabilizing, after which we eventually see ALL_ADS_COMPLETED. In foreground, AD_PROGRESS logs arrive at a dense millisecond-level cadence; when switching to background, AD_PROGRESS slows to ~1s intervals even though the ad audio keeps playing normally.
Repro steps
- Prepare a single preroll (~10s) via MediaItem.AdsConfiguration (IMA tag).
- Player + ImaAdsLoader live inside a MediaLibraryService (background playback enabled).
- Start playback in foreground.
- While preroll is running, send app to background.
- Wait for the ad media to finish.
- Observe: content starts briefly, then preroll restarts (repeat a few times).
Logs (abridged)
Foreground (works as expected):
... STARTED
... AD_PROGRESS (dense millisecond-ish cadence)
... FIRST_QUARTILE / MIDPOINT / THIRD_QUARTILE
... COMPLETED
... CONTENT_RESUME_REQUESTED
... ALL_ADS_COMPLETED
Background (problem case):
... STARTED
... AD_PROGRESS (~1s cadence while backgrounded; ad audio keeps playing)
-- no COMPLETED / no ALL_ADS_COMPLETED while in background --
Content starts ~1–2s, then preroll restarts (loop)
Questions
- Is this expected for video preroll ads in background (i.e., completion/quartile events may not fire while not in view)?
- With Media3 + MediaLibraryService, what is the recommended pattern to avoid preroll replay if the user backgrounded during the ad?
- Are there specific IMA/Media3 callbacks or flags we should honor in background to ensure the ad break is marked complete?
- If background video ads aren’t supported/recommended, what’s the official guidance for apps that support background playback?
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.