How to disable and re-enable all AdsLoader ad breaks without extra buffering
Open
@marcbaechinger is already working on this.
Since Apr 29, 2025.
needs triage
question
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
This issue is similar to: https://github.com/androidx/media/issues/1892
However we have a case where we should disable all AdsLoader ad breaks temporarily (during "ad immunity period") and then we should re-enable all ad breaks again. Currently this is done by setting the ad breaks as skipped:
private fun disableAds() {
var adPlaybackState = adPlaybackState ?: return
for (index in 0 until adPlaybackState.adGroupCount) {
adPlaybackState = adPlaybackState.withSkippedAdGroup(index)
}
this.adPlaybackState = adPlaybackState
}
Later they are re-enabled by resetting them:
private fun enableUpcomingAds(contentPositionMs: Long) {
var adPlaybackState = adPlaybackState ?: return
for (index in 0 until adPlaybackState.adGroupCount) {
if (playedAdBreakIndices.contains(index)) continue
val adGroupStartTimeMs = adPlaybackState.getAdGroup(index).timeUs.usToMs
if (adGroupStartTimeMs > contentPositionMs) {
Timber.d("Re-enabled ad break #${index}")
adPlaybackState = adPlaybackState.withResetAdGroup(index)
}
}
this.adPlaybackState = adPlaybackState
}
However this sometimes causes 1 second buffering and dropped frames. Is the correct solution to re-add all ad breaks or is there a better way?
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.