书签
本指南介绍了如何使用 IMA DAI SDK 实现书签功能
。
这里假定一个有效的 IMA DAI 实现(如
开始使用。
什么是添加书签?
书签是指先保存书签,然后再返回到特定位置
。假设一位用户观看了 5 分钟的内容
离开视频流,然后返回视频流。书签功能可保存
用户在视频流中的位置,以便流式传输能够从其位置
从而为观看者提供顺畅的体验
DAI 书签功能探秘
为 DAI 视频流添加书签时,您必须记录视频流 ID 和时间
当用户离开视频时触发。当用户返回时,系统会重新请求
流式传输并跳转至保存的时间。由于请求的
只需保存视频流即可设置不同时长的广告插播时间点
时间不会行。您真正想做的是
内容时间。
需要解决的转换方法
IMA DAI SDK 提供了两种方法来请求内容时间
特定直播时间以及特定内容的直播时间
时间。借助这些转换方法,您可以存储已添加书签的
content time,然后定位到
流的新实例。方法如下所示,包括一个链接
到一个示例应用,该应用展示了有效的书签添加实现。
保存书签
在 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.
}
}
示例应用
下载示例应用
查看书签实施。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-10-14。
[null,null,["最后更新时间 (UTC):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"]]