返回到跳过的广告插播时间点
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
作为视频发布商,您可能希望阻止观看者
可让您跳过中贴片广告如果用户跳过广告插播时间点,
则可以返回广告插播时间点的开头,然后返回
在广告插播结束后,将用户跳转到其跳转位置。这个
这个功能叫做“snapback”。
有关示例,请参见下图。你的观看者正在观看视频
并决定从 5 分钟标记跳到 15 分钟标记之间。
不过,您希望观看者在 10 分钟时刻观看广告插播内容,然后才能观看后续内容:

要展示此广告插播时间点,请按以下步骤操作:
- 检查用户运行的搜索是否跳过了未观看的广告插播时间点;
如果是,则将他们返回到广告插播时间点。
- 广告插播结束后,将其返回其原始跳转模式。
以图表形式显示的数据如下所示:

下面介绍了如何使用 IMA DAI SDK 实现回弹,如 AdvancedExample 中所示。
防止用户快进导致广告插播时间点未观看
检查用户是否已快进到未观看的广告插播时刻,如果是,则将用户带回广告插播时刻。tvOS 高级示例利用了 AVPlayerViewController
,
它使用委托方法,告知您用户已运行搜索。
如果跳转开始时间早于上一个广告插播时间点(即,
且尚未播放广告插播时间点,
跳转至广告插播时间点的开头。另外,请记录
最初请求在 ad-break-did-end
处理程序中稍后进行检查:
- (void)playerViewController:(AVPlayerViewController *)playerViewController
willResumePlaybackAfterUserNavigatedFromTime:(CMTime)oldTime
toTime:(CMTime)targetTime {
if (self.streamManager) {
IMACuepoint *prevCuepoint = [self.streamManager
previousCuepointForStreamTime:CMTimeGetSeconds(targetTime)];
if (prevCuepoint && !prevCuepoint.isPlayed && oldTime < prevCuepoint.startTime) {
self.userSeekTime = CMTimeGetSeconds(targetTime);
[self.playerViewController.player seekToTime:CMTimeMakeWithSeconds(
prevCuepoint.startTime, NSEC_PER_SEC)
toleranceBefore:kCMTimeZero
toleranceAfter:kCMTimeZero];
}
}
}
让用户回到其原始跳转
在事件委托中,修改 AD_BREAK_ENDED
情况,检查
先前的广告插播时间点由于跳回而播放。
- (void)streamManager:(IMAStreamManager *)streamManager didReceiveAdEvent:(IMAAdEvent *)event {
NSLog(@"StreamManager event (%@).", event.typeString);
switch (event.type) {
// Your other events go here as normal.
case kIMAAdEvent_AD_BREAK_ENDED: {
if (self.userSeekTime > 0) {
self.playerViewController.player
seekToTime:CMTimeMakeWithSeconds(self.userSeekTime, NSEC_PER_SEC)
toleranceBefore:kCMTimeZero
toleranceAfter:kCMTimeZero];
self.userSeekTime = 0;
// existing handling for AD_BREAK_ENDED goes here.
break;
}
// And so on for other events.
default:
break;
}
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-21。
[null,null,["最后更新时间 (UTC):2025-08-21。"],[[["\u003cp\u003eSnapback prevents viewers from skipping mid-roll ads by returning them to the start of the ad break if they attempt to seek past it.\u003c/p\u003e\n"],["\u003cp\u003eWhen snapback is implemented, viewers are taken back to the ad and then returned to their original seek location after the ad break completes.\u003c/p\u003e\n"],["\u003cp\u003eThis feature utilizes the IMA DAI SDK and involves checking for seeks past unwatched ad breaks and redirecting the viewer accordingly.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can implement snapback by leveraging the \u003ccode\u003eAVPlayerViewController\u003c/code\u003e delegate and modifying the \u003ccode\u003eAD_BREAK_ENDED\u003c/code\u003e event handling in the IMA DAI SDK.\u003c/p\u003e\n"]]],[],null,["# Return to a skipped ad break\n\nAs a video publisher, you may want to prevent your viewers from\nseeking past your mid-roll ads. When a user seeks past an ad break,\nyou can take them back to the start of that ad break, and then return\nthem to their seek location after that ad break has completed. This\nfeature is called \"snapback.\"\n\nAs an example, see the diagram below. Your viewer is watching a video,\nand decides to seek from the 5-minute mark to the 15-minute mark.\nThere is, however, an ad break at the 10-minute mark that you want\nthem to watch before they can watch the content after it:\n\nIn order to show this ad break, take the following steps:\n\n1. Check if the user ran a seek that jumped past an unwatched ad break, and if so, take them back to the ad break.\n2. After the ad break completes, return them to their original seek.\n\nIn diagram form, that looks like this:\n\nHere's how to implement snapback using the IMA DAI SDK, as demonstrated in\n[AdvancedExample](//github.com/googleads/googleads-ima-tvos-dai).\n\nPrevent a seek from leaving an ad break unwatched\n-------------------------------------------------\n\nCheck if the user has run a seek that went past an unwatched ad break,\nand if so, take them back to the ad break.\nThe tvOS advanced example takes advantage of the `AVPlayerViewController`,\nwhich has a delegate method to tell you that the user has run a seek.\nIf the seek start time comes before the previous ad break (meaning\nthe user has jumped past it) and that break hasn't yet been played,\nseek them back to the start of the ad break. Also, record the start time of the\ninitially requested seek to check later in your `ad-break-did-end` handler: \n\n```css+lasso\n- (void)playerViewController:(AVPlayerViewController *)playerViewController\n willResumePlaybackAfterUserNavigatedFromTime:(CMTime)oldTime\n toTime:(CMTime)targetTime {\n if (self.streamManager) {\n IMACuepoint *prevCuepoint = [self.streamManager\n previousCuepointForStreamTime:CMTimeGetSeconds(targetTime)];\n if (prevCuepoint && !prevCuepoint.isPlayed && oldTime \u003c prevCuepoint.startTime) {\n self.userSeekTime = CMTimeGetSeconds(targetTime);\n [self.playerViewController.player seekToTime:CMTimeMakeWithSeconds(\n prevCuepoint.startTime, NSEC_PER_SEC)\n toleranceBefore:kCMTimeZero\n toleranceAfter:kCMTimeZero];\n }\n }\n}\n```\n\nPut the user back to their original seek\n----------------------------------------\n\nIn your event delegate, modify the `AD_BREAK_ENDED` case to check if the\nprevious ad break was played as the result of snapback. \n\n```objective-c\n\n- (void)streamManager:(IMAStreamManager *)streamManager didReceiveAdEvent:(IMAAdEvent *)event {\n NSLog(@\"StreamManager event (%@).\", event.typeString);\n switch (event.type) {\n // Your other events go here as normal.\n case kIMAAdEvent_AD_BREAK_ENDED: {\n if (self.userSeekTime \u003e 0) {\n self.playerViewController.player\n seekToTime:CMTimeMakeWithSeconds(self.userSeekTime, NSEC_PER_SEC)\n toleranceBefore:kCMTimeZero\n toleranceAfter:kCMTimeZero];\n self.userSeekTime = 0;\n\n // existing handling for AD_BREAK_ENDED goes here.\n break;\n }\n // And so on for other events.\n default:\n break;\n }\n}\n```"]]