如何使用 AVInterstitialTimeRange 在 TVOS 上展示广告?

How to show ads on TVOS using AVInterstitialTimeRange?

播放电影时,我想使用 AVInterstitialTimeRange 显示一些广告。我可以在播放电影时在进度条上创建"dots",但我如何实际展示广告?

到目前为止,这是我展示广告的代码。

 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(强调已加):

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 an AVPlayerItem object you present with the AVPlayerViewController 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.

翻译:您不会使用此 API 来 展示 广告。您将广告作为与您的内容相同的媒体流的一部分呈现,或者可能通过一个 AVPlayerItem 播放多个来源的组合。

如果您已经展示了插页式内容,您希望在UI中清楚地标记此类内容对应的时间范围(以便于跳过或禁止跳过),您可以使用AVInterstitialTimeRange 标记它们。