儲存及載入廣告串流書籤
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本指南說明如何使用 IMA DAI SDK 導入書籤功能
在隨選影片 (VOD) 串流中使用動態廣告插播 (DAI) 時。
本文會假設 IMA DAI 導入成功,例如
開始使用。
什麼是書籤?
書籤可讓使用者儲存並回到特定時間點
內容串流中。假設某位使用者觀看了五分鐘的內容
離開影片串流,然後返回該串流加入書籤可儲存
以便繼續觀看
讓觀眾享有流暢的觀看體驗。
DAI 內部書籤
將 DAI 串流加入書籤時,您必須記錄串流 ID 和時間
使用者離開影片時。當使用者回訪時,請重新提出要求
播放串流,然後跳轉至已儲存的時間。因為請求的每個執行個體
多個串流的廣告插播時間點只要儲存
根本無法運作但不打算想要做什麼
內容時間。
因應之道的轉換方法
IMA DAI SDK 提供一組方法,用來請求內容時間
特定內容的串流時間及串流時間的內容
時間。使用這些轉換方法,您就能將
內容時間,然後跳轉至對應的串流時間,
新的串流執行個體做法如下,包括連結
以便在某個範例應用程式中,顯示可正常運作的書籤。
正在儲存書籤
在活動暫停時儲存書籤。
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.contentPlayer pause];
// Ignore this if you're presenting a modal view (e.g. in-app clickthrough).
if ([self.navigationController.viewControllers indexOfObject:self] ==
NSNotFound) {
NSTimeInterval contentTime =
[self.streamManager contentTimeForStreamTime:CMTimeGetSeconds(
self.contentPlayer.currentTime)];
self.video.savedTime = contentTime;
...
}
}
}
正在載入書籤
在重新要求直播時載入書籤。這個容器是將容器
VideoStreamPlayer
介面。
- (void)streamManager:(IMAStreamManager *)streamManager didReceiveAdEvent:(IMAAdEvent *)event {
...
case kIMAAdEvent_STREAM_LOADED: {
if (self.video.savedTime > 0) {
NSTimeInterval streamTime =
[self.streamManager streamTimeForContentTime:self.video.savedTime];
[self.IMAVideoDisplay.playerItem
seekToTime:CMTimeMakeWithSeconds(streamTime, NSEC_PER_SEC)];
self.video.savedTime = 0;
}
}
}
範例應用程式
範例應用程式
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-21 (世界標準時間)。
[null,null,["上次更新時間:2025-08-21 (世界標準時間)。"],[[["\u003cp\u003eThis guide explains how to implement bookmarking in video-on-demand (VOD) streams using the IMA DAI SDK for a seamless viewing experience.\u003c/p\u003e\n"],["\u003cp\u003eBookmarking involves saving the user's content time, not just the stream time, to ensure accurate resumption upon return.\u003c/p\u003e\n"],["\u003cp\u003eThe IMA DAI SDK provides methods to convert between stream time and content time, which are crucial for bookmarking functionality.\u003c/p\u003e\n"],["\u003cp\u003eSaving bookmarks involves recording the content time when the user pauses the video, while loading bookmarks requires seeking to the corresponding stream time in the new stream instance.\u003c/p\u003e\n"],["\u003cp\u003eA sample app demonstrating bookmarking implementation is available on GitHub.\u003c/p\u003e\n"]]],["Bookmarking in Dynamic Ad Insertion (DAI) involves saving a user's position in a video stream and resuming from that point. Instead of saving stream time, the system records the content time using conversion methods provided by the IMA DAI SDK. When the user leaves, the content time is saved. Upon return, the saved content time is used to calculate the new stream time, allowing seeking to the correct point in the stream. The process is demonstrated with sample code and a provided sample application.\n"],null,["# Save and load ad stream bookmarks\n\nThis guide shows how to implement bookmarking using the IMA DAI SDK\nwhen using Dynamic Ad Insertion (DAI) for video-on-demand (VOD) streams.\nThis assumes a working IMA DAI implementation, such as the one presented in\n\n\n[Get Started](/interactive-media-ads/docs/sdks/ios/dai-quickstart).\n\n\nWhat is bookmarking?\n--------------------\n\nBookmarking is the ability to save and then return to a specific point\nin the content stream. Suppose a user watches five minutes of content,\nleaves the video stream, and then returns to it. Bookmarking saves the\nuser's position in the stream so the stream can pick up from where it\nleft off, providing a seamless experience to the viewer.\n\nDAI bookmarking under the hood\n------------------------------\n\nWhen bookmarking a DAI stream, you must record the stream id and time\nwhen the user leaves the video. When the user returns, re-request the\nstream and seek to the saved time. Since each instance of the requested\nstream can have ad breaks of different durations simply saving the stream\ntime won't work. What you really want to do is continue from the same\n**content time**.\n\nConversion methods to the rescue\n--------------------------------\n\nThe IMA DAI SDK provides a pair of methods to request the **content time**\nfor a given **stream time** and the **stream time** for a given **content\ntime** . Using these conversion methods you can store the bookmarked\n**content time** and then seek to the corresponding **stream time** in\nthe new instance of the stream. Here's the approach, including a link\nto a sample app that shows a working bookmarking implementation.\n\nSaving bookmarks\n----------------\n\nSave a bookmark when the Activity is paused. \n\n - (void)viewWillDisappear:(BOOL)animated {\n [super viewWillDisappear:animated];\n [self.contentPlayer pause];\n // Ignore this if you're presenting a modal view (e.g. in-app clickthrough).\n if ([self.navigationController.viewControllers indexOfObject:self] ==\n NSNotFound) {\n NSTimeInterval contentTime =\n [self.streamManager contentTimeForStreamTime:CMTimeGetSeconds(\n self.contentPlayer.currentTime)];\n self.video.savedTime = contentTime;\n ...\n }\n }\n }\n\nLoading bookmarks\n-----------------\n\nLoad the bookmark when re-requesting a stream. It's part of implementing\nthe `VideoStreamPlayer` interface. \n\n - (void)streamManager:(IMAStreamManager *)streamManager didReceiveAdEvent:(IMAAdEvent *)event {\n ...\n case kIMAAdEvent_STREAM_LOADED: {\n if (self.video.savedTime \u003e 0) {\n NSTimeInterval streamTime =\n [self.streamManager streamTimeForContentTime:self.video.savedTime];\n [self.IMAVideoDisplay.playerItem\n seekToTime:CMTimeMakeWithSeconds(streamTime, NSEC_PER_SEC)];\n self.video.savedTime = 0;\n }\n }\n }\n\nSample app\n----------\n\n[Sample app](//github.com/googleads/googleads-ima-ios-dai)"]]