androidx / androidx/media

Media3 + IMA: In background, ad audio finishes but AD events don’t complete (no ALL_ADS_COMPLETED) → preroll restarts

Open
#2,801 1 comment 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Sep 24, 2025.

question
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

  1. Prepare a single preroll (~10s) via MediaItem.AdsConfiguration (IMA tag).
  2. Player + ImaAdsLoader live inside a MediaLibraryService (background playback enabled).
  3. Start playback in foreground.
  4. While preroll is running, send app to background.
  5. Wait for the ad media to finish.
  6. 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

  1. Is this expected for video preroll ads in background (i.e., completion/quartile events may not fire while not in view)?
  2. With Media3 + MediaLibraryService, what is the recommended pattern to avoid preroll replay if the user backgrounded during the ad?
  3. Are there specific IMA/Media3 callbacks or flags we should honor in background to ensure the ad break is marked complete?
  4. If background video ads aren’t supported/recommended, what’s the official guidance for apps that support background playback?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.