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

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

下面展示了如何使用 IMA DAI SDK 实现 Snapack,如我们的
高级示例。
防止用户快进导致广告插播时间点未观看
检查用户运行的搜索是否跳过了未观看的广告插播时间点,
如果是,则将他们返回到广告插播时间点。
Roku 高级示例依靠遥控器按钮来实现
用户要查找路径 - 每次用户按下前进按钮时,
向前跳转指定的秒数。相同
处理此跳转的方法也会检查跳转是否
用户跳过或进入广告插播时间点;如果是,则向用户发送
改为插入广告插播时间点的开头:
Function handleFastForward(player as Object, streamManager as Object, updatedTime As Integer)
previousAd = streamManager.getPreviousCuePoint(updatedTime)
If previousAd = Invalid or previousAd.hasPlayed
player.seek(updatedTime * 1000)
Else If previousAd.start > player.currentTime
player.isSnapback = True
player.timeAfterSnapback = updatedTime
player.seek(previousAd.start * 1000 + 1000)
End If
End Function
让用户回到其原始跳转
在您的 adBreakEnded
处理程序中,检查上一个广告
因为快速回弹导致播放中断如果是,则返回
用户到达他们最初尝试尝试的位置(只要
因为不是刚刚播放的广告插播时间点的中间):
player.adBreakEnded = Function(adBreakInfo as Object)
If m.isSnapback
m.seek(m.timeAfterSnapback * 1000)
m.isSnapback = False
End If
End Function
如未另行说明,那么本页面中的内容已根据知识共享署名 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 triggered, viewers are taken back to the ad and then returned to their original seek location after the ad completes.\u003c/p\u003e\n"],["\u003cp\u003eImplementing snapback involves checking for seeks past unwatched ad breaks and redirecting the viewer, then returning them to their desired location afterwards.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code snippets demonstrate how to implement snapback using the IMA DAI SDK, handling seek events and ad break endings.\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 snapack using the IMA DAI SDK, as demonstrated in our\n[Advanced Example](//github.com/googleads/googleads-ima-roku-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 Roku advanced sample relies on remote button presses for the\nuser to seek - each time the user presses the forward button, they\njump forward in the stream by a set number of seconds. The same\nmethod that handles this jump also checks to see if the jump\ntakes/ them past or into an ad break, and if it does, sends the user\nto the start of that ad break instead: \n\n Function handleFastForward(player as Object, streamManager as Object, updatedTime As Integer)\n previousAd = streamManager.getPreviousCuePoint(updatedTime)\n If previousAd = Invalid or previousAd.hasPlayed\n player.seek(updatedTime * 1000)\n Else If previousAd.start \u003e player.currentTime\n player.isSnapback = True\n player.timeAfterSnapback = updatedTime\n player.seek(previousAd.start * 1000 + 1000)\n End If\n End Function\n\nPut the user back to their original seek\n----------------------------------------\n\nIn your `adBreakEnded` handler, check to see if the previous ad\nbreak was played as the result of snapback. If so, return the\nuser to the place they were trying to seek to initially (as long\nas it wasn't the middle of the ad break that just played): \n\n player.adBreakEnded = Function(adBreakInfo as Object)\n If m.isSnapback\n m.seek(m.timeAfterSnapback * 1000)\n m.isSnapback = False\n End If\n End Function"]]