youtube-api - 如何检索 YouTube 上直播事件的开始时间?

标签 youtube-api youtube-javascript-api

我正在尝试返回并将已完成或正在进行的直播事件与真实世界的时间戳同步(例如,推特直播。)我不拥有相关直播事件。显然这仅对可以倒带或重放的事件有用(例如许多与游戏相关的广播)

有没有办法检索直播事件的开始时间?

我试过以下方法:

使用 player.getDuration():

If the currently playing video is a live event, the getDuration() function will return the elapsed time since the live video stream began. Specifically, this is the amount of time that the video has streamed without being reset or interrupted. In addition, this duration is commonly longer than the actual event time since streaming may begin before the event's start time.

这似乎并不总是准确的 - 如果直播事件有设置的广播持续时间,这似乎会返回广播安排的总时间。这是一个表现出这种行为的随机视频:http://www.youtube.com/watch?v=e-Bb5F8Jcwg (通过 http://www.youtube.com/live/all 找到)

我也尝试过使用数据 api 并从片段中获取发布时间,但这通常看起来是广播实际开始前的几个小时或几天。

作为非内容拥有者,有什么办法可以找回这个时间吗?

谢谢!

编辑:
进一步查看后,我发现 developers.google.com/youtube/2.0/... 它似乎在 yt:when 下为每个事件提供此信息...所以我想我修改后的问题是 - 有没有办法检索这个给定一个视频 ID,还是我总是需要通过实时事件 API 找到它?

最佳答案

您可以使用 Data API v3为此。

你可以做一个videos->list with id=VIDEO_ID

您可以从 contentDetails.duration 获取持续时间from the response.


如果内容是您自己的,您可以使用 v3 Live Streaming API为此。

你可以做一个liveBroadcasts->list with id=VIDEO_ID

您可以使用 snippet.actualStartTime 计算持续时间和 snippet.actualEndTime from the response.

关于youtube-api - 如何检索 YouTube 上直播事件的开始时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18068378/

相关文章:

YouTube Iframe-API : getting the iframe-id inside 'onStateChange' function

javascript - 当使用 Javascript 关闭(隐藏)div 时停止 YouTube 视频播放

api - 我可以在已经在服务器上获得授权的客户端上自动登录用户吗?

javascript - Jquery TubePlayer 插件未按预期运行

javascript - 通过 JavaScript 让 YouTube 播放器全屏显示

javascript - 使用 YoutubeAPI 播放 youtube 视频直到特定时间并暂停

youtube - Youtube Flash Player getDuration不正确

javascript - YouTube 视频在向下滚动或粘滞时静音但仍在播放

youtube - 在YouTube播放列表的末尾添加视频 “on fly”

javascript - 如何在 Cocoa 应用程序中加载/暂停/恢复 YouTube 视频?