When playing a movie, I would like to show some ads using AVInterstitialTimeRange. I was able to create the "dots" on the progress bar when playing the movie, but how do I actually present the ads?
so far this is my code to present the ads.
NSArray *adBreaks = result.adBreaks;
_player.player.currentItem.interstitialTimeRanges = adBreaks;
NSMutableArray *adBreaksCMTime = [[NSMutableArray alloc]init];
for(AdBreak *brk in adBreaks) {
CMTime seekingCM = CMTimeMake([brk adBreakTime], 1);
CMTime durationCM = CMTimeMake([brk adBreakDuration], 1);
AVInterstitialTimeRange *adTimeRange = [[AVInterstitialTimeRange alloc]initWithTimeRange:CMTimeRangeMake(seekingCM, durationCM)];
[adBreaksCMTime addObject:adTimeRange];
}
_player.player.currentItem.interstitialTimeRanges = adBreaksCMTime;
Quoth the docs (emphasis added):
An
AVInterstitialTimeRange
object identifies a time range in an audiovisual presentation as interstitial content, such as advertisements or legal notices. By associating interstitial time ranges with anAVPlayerItem
object you present with theAVPlayerViewController
class, you can customize or restrict the presentation of interstitial content. For example, you can allow the user to easily skip advertisements or prohibit skipping of a legal notice.
Translation: you don't use this API to present ads. You present ads as part of the same media stream as your content, or perhaps through a composition of several sources played through one AVPlayerItem
.
If, once you're already presenting interstitial content, you want the time ranges corresponding to such content to be clearly marked in the UI (for easy skipping or to prohibit skipping), you can use AVInterstitialTimeRange
to mark them.