กลับไปที่ช่วงพักโฆษณาที่ข้าม
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ในฐานะผู้เผยแพร่วิดีโอ คุณอาจต้องการป้องกันไม่ให้ผู้ชม
ที่ผ่านโฆษณาตอนกลางของคุณ เมื่อผู้ใช้กรอผ่านช่วงพักโฆษณา
คุณสามารถนำหน่วยโฆษณากลับไปยังจุดเริ่มต้นของช่วงพักโฆษณา แล้วค่อยกลับมาที่หน้านี้
ไปยังตำแหน่งที่ผู้ใช้ค้นหาหลังจากช่วงพักโฆษณาสิ้นสุดลง ฟีเจอร์นี้เรียกว่า "การย้อนกลับ"
โปรดดูแผนภาพด้านล่างเป็นตัวอย่าง ผู้ชมของคุณกำลังดูวิดีโอ
และตัดสินใจค้นหาจากช่วง 5 นาทีจนถึง 15 นาที
อย่างไรก็ตาม มีช่วงพักโฆษณาในช่วงเวลา 10 นาทีที่คุณต้องการ
ในการรับชมก่อนที่จะได้รับชมเนื้อหาหลังจากนั้น:

หากต้องการแสดงช่วงพักโฆษณา ให้ทำตามขั้นตอนต่อไปนี้
- ตรวจสอบว่าผู้ใช้ทำการค้นหาที่ข้ามผ่านช่วงพักโฆษณาที่ยังไม่ได้ดูหรือไม่
ให้ย้อนกลับไปที่ช่วงพักโฆษณา
- หลังจากช่วงพักโฆษณาสิ้นสุดลง ให้นำโฆษณากลับไปยังกรอวิดีโอเดิม
ในรูปแบบแผนภาพ จะมีลักษณะดังนี้

ต่อไปนี้เป็นวิธีใช้เวิร์กโฟลว์นี้ใน IMA DAI SDK ตามที่ทำใน
AdvancedExample
ป้องกันไม่ให้ระบบเลิกดูช่วงพักโฆษณา
ตรวจสอบว่าผู้ใช้ได้ทำการค้นหาที่ผ่านช่วงพักโฆษณาที่ไม่ได้ดูไปแล้วหรือไม่
ให้ย้อนกลับไปที่ช่วงพักโฆษณา
ในตัวอย่างขั้นสูงของ iOS ให้ใช้การโต้ตอบของผู้ใช้กับ UI ของคุณ
เพื่อตรวจจับเมื่อได้ทำการค้นหา เก็บเวลาเริ่มต้นของการกรอเพื่อตรวจสอบว่าผู้ใช้ข้ามช่วงพักโฆษณาที่ไม่ได้เล่นไปหรือไม่ เมื่อผู้ใช้
ปล่อยการควบคุมวิดีโอ เปรียบเทียบเวลาปัจจุบันกับเวลา
ช่วงพักโฆษณาล่าสุด หากช่วงพักโฆษณาอยู่หลังช่วงเริ่มต้นการกรอวิดีโอ
(หมายความว่าผู้ใช้ได้ข้ามผ่านไปแล้ว) และยังไม่มีการเล่น
ย้อนกลับไปที่จุดเริ่มต้นของช่วงพักโฆษณา และตั้งค่าสถานะของ Snapback
หากต้องการตรวจสอบภายหลังในเครื่องจัดการช่วงพักโฆษณาที่สมบูรณ์
- (IBAction)videoControlsTouchStarted:(id)sender {
self.seekStartTime = self.contentPlayer.currentTime;
}
- (IBAction)videoControlsTouchEnded:(id)sender {
self.seekEndTime = CMTimeMake(self.progressBar.value, 1);
IMACuepoint *lastCuepoint =
[self.streamManager previousCuepointForStreamTime:CMTimeGetSeconds(self.seekEndTime)];
if (!lastCuepoint.played && (lastCuepoint.startTime > CMTimeGetSeconds(self.seekStartTime))) {
self.snapbackMode = YES
// Add 1 to the seek time to get the keyframe at the start of the ad to be your landing place.
[self.contentPlayer seekToTime:CMTimeMakeWithSeconds(lastCuepoint.startTime + 1, NSEC_PER_SEC)];
}
}
นำผู้ใช้กลับไปยังการค้นหาเดิม
ในเครื่องจัดการที่มีการหยุดโฆษณา ให้ตรวจสอบว่า
เล่น break จากผลของ Snapback ในกรณีนี้ ให้ส่งคืนผู้ใช้
ให้กับสถานที่ที่พวกเขาพยายามจะ ได้ในตอนแรก (หาก
ไม่ได้อยู่ตรงกลางของช่วงพักโฆษณาที่เพิ่งเล่นไป):
- (void)streamManager:(IMAStreamManager *)streamManager didReceiveAdEvent:(IMAAdEvent *)event {
switch (event.type) {
case kIMAAdEvent_AD_BREAK_ENDED: {
if (self.snapbackMode) {
self.snapbackMode = NO;
if (CMTimeCompare(self.seekEndTime, self.contentPlayer.currentTime)) {
[self.contentPlayer seekToTime:self.seekEndTime];
}
}
break;
}
}
}
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-21 UTC
[null,null,["อัปเดตล่าสุด 2025-08-21 UTC"],[[["\u003cp\u003eSnapback prevents viewers from skipping mid-roll ads by returning them to the start of the ad break if they seek past it.\u003c/p\u003e\n"],["\u003cp\u003eWhen a viewer seeks past an unwatched ad, the feature takes them back to the ad and then returns them to their intended location after the ad completes.\u003c/p\u003e\n"],["\u003cp\u003eImplementing snapback involves checking for seeks that bypass unwatched ads and using ad break event handlers to redirect the viewer accordingly.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code snippets demonstrate how to detect ad-skipping seeks and trigger the snapback functionality within 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 this workflow in the IMA DAI SDK, as done in the\n[AdvancedExample](//github.com/googleads/googleads-ima-ios-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.\nFor the iOS Advanced example, use the user's interaction with your UI\nto detect when they have run a seek. Preserve the seek start time to check\nif they've passed an unplayed ad break in their seek. When the user\nreleases the video controls, compare their current time to the time of\nthe most recent ad break. If the ad break falls after the seek start\ntime (meaning the user has jumped past it) and it hasn't yet been played,\nseek them back to the start of the ad break. Also, set a snapback flag\nto check later in your ad break complete handler: \n\n - (IBAction)videoControlsTouchStarted:(id)sender {\n self.seekStartTime = self.contentPlayer.currentTime;\n }\n\n - (IBAction)videoControlsTouchEnded:(id)sender {\n self.seekEndTime = CMTimeMake(self.progressBar.value, 1);\n IMACuepoint *lastCuepoint =\n [self.streamManager previousCuepointForStreamTime:CMTimeGetSeconds(self.seekEndTime)];\n if (!lastCuepoint.played && (lastCuepoint.startTime \u003e CMTimeGetSeconds(self.seekStartTime))) {\n self.snapbackMode = YES\n // Add 1 to the seek time to get the keyframe at the start of the ad to be your landing place.\n [self.contentPlayer seekToTime:CMTimeMakeWithSeconds(lastCuepoint.startTime + 1, NSEC_PER_SEC)];\n }\n }\n\nPut the user back to their original seek\n----------------------------------------\n\nIn your ad-break-ended handler, check to see if the previous\nbreak was played as the result of snapback. If so, return the user\nto the place they were trying to seek to initially (as long as it\nwasn't the middle of the ad break that just played): \n\n - (void)streamManager:(IMAStreamManager *)streamManager didReceiveAdEvent:(IMAAdEvent *)event {\n switch (event.type) {\n case kIMAAdEvent_AD_BREAK_ENDED: {\n if (self.snapbackMode) {\n self.snapbackMode = NO;\n if (CMTimeCompare(self.seekEndTime, self.contentPlayer.currentTime)) {\n [self.contentPlayer seekToTime:self.seekEndTime];\n }\n }\n break;\n }\n }\n }"]]