書籤
本指南說明如何使用 IMA DAI SDK 導入書籤功能
在隨選影片 (VOD) 串流中使用動態廣告插播 (DAI) 時。
本文會假設 IMA DAI 導入成功,例如
開始使用。
什麼是書籤?
書籤可讓使用者儲存並回到特定時間點
內容串流中。假設某位使用者觀看了五分鐘的內容
離開影片串流,然後返回該串流加入書籤可儲存
以便繼續觀看
讓觀眾享有流暢的觀看體驗。
DAI 內部書籤
將 DAI 串流加入書籤時,您必須記錄串流 ID 和時間
使用者離開影片時。當使用者回訪時,請重新提出要求
播放串流,然後跳轉至已儲存的時間。因為請求的每個執行個體
多個串流的廣告插播時間點只要儲存
根本無法運作但不打算想要做什麼
內容時間。
因應之道的轉換方法
IMA DAI SDK 提供一組方法,用來請求內容時間
特定內容的串流時間及串流時間的內容
時間。使用這些轉換方法,您就能將
內容時間,然後跳轉至對應的串流時間,
新的串流執行個體做法如下,包括連結
以便在某個範例應用程式中,顯示可正常運作的書籤。
正在儲存書籤
在 Activity
暫停時儲存書籤。
private double bookmarkTime;
@Override
public void onPause() {
super.onPause();
double streamTime = videoPlayer.getCurrentPosition() / 1000.0; // ms to s.
bookmarkTime = streamManager.getContentTimeForStreamTime(streamTime);
}
正在載入書籤
在重新要求直播時載入書籤。這個容器是將容器
VideoStreamPlayer
介面。
public void loadUrl(String url, List<HashMap<String, String>> subtitles) {
// Set video player's stream URL and subtitles, and play the stream.
...
// Bookmarking.
if (bookmarkTime > 0) {
double streamTime =
streamManager.getStreamTimeForContentTime(bookmarkTime);
videoPlayer.seek((long) (streamTime * 1000.0)); // s to ms.
}
}
範例應用程式
下載範例應用程式
看看書籤的實作情形。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-10-14 (世界標準時間)。
[null,null,["上次更新時間:2024-10-14 (世界標準時間)。"],[[["This guide explains how to implement bookmarking in video-on-demand (VOD) streams using the IMA DAI SDK for a seamless viewing experience."],["Bookmarking involves saving the user's content time, not just stream time, to ensure accurate playback resumption."],["The IMA DAI SDK provides methods to convert between stream time and content time for bookmarking purposes."],["Developers can save bookmarks when the activity is paused and load them when the stream is re-requested."],["A sample app demonstrating bookmarking implementation is available on GitHub."]]],["Bookmarking in IMA DAI involves saving the user's position in a video stream for later continuation. Instead of recording the stream time, the key is to save the content time. When a user leaves, record the stream ID and convert the current stream time to content time using `getContentTimeForStreamTime()`. Upon return, re-request the stream and use `getStreamTimeForContentTime()` to find the corresponding stream time to seek to. Bookmarks are saved when the `Activity` pauses and loaded when re-requesting a stream.\n"]]