php - Youtube API - 确定是否有人开始/结束观看视频
问题描述
关于YouTube API -- 是否可以确定某人是否已开始观看或已完成观看视频?
解决方案
正如您在上面链接的文档中提到的,我建议按照所示执行
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
推荐阅读
- r - 附近观测值的总和
- r - Rcmd 检查:我从未使用过的“:::”调用导入的未导出对象
- ruby-on-rails - 将 Rails 推到 Heroku,找不到 Rake taks
- sql - 转义奇数个撇号?
- c# - C# WPF 帮助 1. 删除列表框中的前两个条目或 2. 阻止它在输出中显示批处理中的命令语法
- javascript - TypeError:Restivus 不是 Vulcan 项目中的构造函数
- firebase - 我刚刚从我的 firebase firestore 数据库中丢失了大量数据,有什么办法可以恢复吗?
- javascript - 如何解决:“类型错误:无法读取 null 的属性 'addEventListener'”...?//
- python-3.x - 如何在 Python 中使用正则表达式搜索来搜索文本块?
- python - 访问方法变量