広告ストリームのブックマークを保存、読み込む
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このガイドでは、ビデオ オンデマンド(VOD)ストリームにダイナミック広告挿入(DAI)を使用する場合に、IMA DAI SDK を使用してブックマークを実装する方法について説明します。これは、スタートガイドで説明されているような、動作する IMA DAI 実装があることを前提としています。
ブックマークとは
ブックマークは、コンテンツ ストリームのあるポイントを保存し、後でそこから再生する機能です。たとえば、ユーザーが 5 分間のコンテンツを見ているとします。動画ストリーム中に視聴を中断して、後で中断したところから再生を再開できます。ブックマークはユーザーが見ていた場所を保存するので、中断したところに戻ってスムーズに視聴を続けられます。
DAI ブックマークの仕組み
DAI ストリームをブックマークする場合は、ストリーム ID と、ユーザーが動画を離れた時刻を記録する必要があります。ユーザーが戻ってきたら、ストリーミングを再リクエストし、保存した時間にシークします。リクエストされたストリームの各インスタンスに異なる長さのミッドロール挿入点が存在する可能性があるため、ストリーム時間を保存するだけでは対応できません。同じコンテンツの時間から続行したい場合。
コンバージョン メソッドの活用
IMA DAI SDK には、特定のストリーム時間のコンテンツ時間と、特定のコンテンツ時間のストリーム時間をリクエストする一対のメソッドが用意されています。これらの変換方法を使用すると、ブックマークしたコンテンツの時間を保存し、ストリームの新しいインスタンスで対応するストリームの時間にシークできます。以下に、ブックマークの実装を示すサンプルアプリへのリンクを含め、アプローチを示します。
広告ストリームのブックマークを保存、読み込む
コンテンツ プレーヤーが一時停止されたときにブックマークを保存します。
onPause() {
var bookmarkTime = Math.floor(
streamManager.contentTimeForStreamTime(videoElement.currentTime));
}
ブックマークを読み込んでいます
ストリームを再リクエストするときにブックマークを読み込む。
function loadUrl(url) {
hls.on(Hls.Events.MANIFEST_PARSED, () => {
var startTime = 0;
if (bookmarkTime) {
var startTime = streamManager.streamTimeForContentTime(bookmarkTime);
// Seeking on load triggers the onSeekEnd event, so treat this seek as
// if it's snapback. Without this, resuming at a bookmark kicks you
// back to the ad before the bookmark.
isSnapback = true;
}
hls.startLoad(startTime);
videoElement.addEventListener('loadedmetadata', () => { videoElement.play(); });
});
hls.loadSource(url);
hls.attachMedia(videoElement);
}
サンプルアプリ
サンプルアプリをダウンロードして、ブックマークの実装を確認します。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-21 UTC。
[null,null,["最終更新日 2025-08-21 UTC。"],[[["\u003cp\u003eThis guide explains how to implement bookmarking in video-on-demand (VOD) streams using the IMA DAI SDK for a seamless viewing experience when users return to previously watched content.\u003c/p\u003e\n"],["\u003cp\u003eBookmarking with DAI involves saving the content time, not the stream time, to ensure accurate resumption due to potential ad break variations.\u003c/p\u003e\n"],["\u003cp\u003eThe IMA DAI SDK provides methods \u003ccode\u003econtentTimeForStreamTime\u003c/code\u003e and \u003ccode\u003estreamTimeForContentTime\u003c/code\u003e to convert between stream and content time for bookmarking functionality.\u003c/p\u003e\n"],["\u003cp\u003eA sample app demonstrating a working bookmarking implementation is available for download and reference.\u003c/p\u003e\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[Get Started](/interactive-media-ads/docs/sdks/html5/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\nSave and load ad stream bookmarks\n---------------------------------\n\nSave a bookmark when the content player is paused. \n\n onPause() {\n var bookmarkTime = Math.floor(\n streamManager.contentTimeForStreamTime(videoElement.currentTime));\n }\n\nLoading bookmarks\n-----------------\n\nLoad the bookmark when re-requesting a stream. \n\n function loadUrl(url) {\n hls.on(Hls.Events.MANIFEST_PARSED, () =\u003e {\n var startTime = 0;\n if (bookmarkTime) {\n var startTime = streamManager.streamTimeForContentTime(bookmarkTime);\n // Seeking on load triggers the onSeekEnd event, so treat this seek as\n // if it's snapback. Without this, resuming at a bookmark kicks you\n // back to the ad before the bookmark.\n isSnapback = true;\n }\n hls.startLoad(startTime);\n videoElement.addEventListener('loadedmetadata', () =\u003e { videoElement.play(); });\n });\n hls.loadSource(url);\n hls.attachMedia(videoElement);\n }\n\nSample app\n----------\n\n[Download the Sample app](//github.com/googleads/googleads-ima-html5-dai)\nto see a bookmarking implementation."]]