Cannot control behaviour of ads in AdsMediaSource
- Dominant language
- Java
- Stars
- 21.9k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
### Issue description
It should be possible to control whether an ad plays at the point of seeking. Currently, ANY seek results in a previous ad playing. We only want ads to play if the time hits the ad start time.
### Reproduction steps
I have a set of ads, defined manually using:
```
ArrayList ads = ...
long[] times = new long[ads.size()];
for (int i = 0; i < ads.size(); i++) {
times[i] = (long) ads.get(i)[Movie.ADS_TIME_INDEX] * 1000000;
}
mAdPlaybackState = new AdPlaybackState(times);
for (int i = 0; i < ads.size(); i++) {
mAdPlaybackState.adGroups[i] = mAdPlaybackState.adGroups[i].withAdCount(1);
mAdPlaybackState.adGroups[i] = mAdPlaybackState.adGroups[i].withAdUri(Uri.parse((String) ads.get(i)[Movie.ADS_URL]), 0);
}
eventListener.onAdPlaybackState(mAdPlaybackState);
```
Which works fine if you just let it play though. But as soon as you start seeking, it always plays a previous ad (if there is one). We should have more control over this.
I have tried a number of work arounds, such as changing the AdPlaybackState, but this seems to muck up the timeline as the number of periods is wrong.
I have also tried just changing the media source provided so that it passes a 0-length source if it shouldn't be playing ads. But this doesn't work because it remembers the AdMediaSources once they are created.
### Link to test content
This behaviour happens with any HLS stream as the main stream and the ads we use are MP4.
### Version of ExoPlayer being used
2.7.1
### Device(s) and version(s) of Android being used
OnePlus 5, Android 8.0
### A full bug report captured from the device
N/A
Contributor guide
Assessment
This issue has not been assessed yet.