【发布时间】:2019-11-25 10:11:56
【问题描述】:
我正在尝试使用 Spotify Web API(https://developer.spotify.com/documentation/web-api/reference/) 为音乐创建很酷的可视化。
我正在尝试的是首先获取用户正在播放的内容,他们的进度,然后我也获取曲目分析。
可以在这个端点上获取当前播放的歌曲:https://developer.spotify.com/documentation/web-api/reference/player/get-the-users-currently-playing-track/
回复中对我来说重要的东西基本上是这样的:
{
"id": H7sbas7Gda98sh...., //ID of the song
"timestamp": 1490252122574, //unix timestamp when the data is fetched
"progress_ms": 42567 //The progress of the track in milliseconds
}
很明显,从请求到我在应用程序中解析响应的时间间隔了一段时间。所以计划是我这样同步音乐:
const auto current_time = get_current_unix_timestamp();
const auto difference = current_time - timestamp; //the timestamp that is in the response
const offset = progress_ms + difference; //the progress_ms that is in the response
这个理论很酷,但似乎服务器和我的系统之间的时钟不同步,因为我通常会得到像 -1638 这样的值来表示差异,这显然不好,因为这意味着我比它更快地解析数据已获取。
所以我的问题是,我有哪些选项可以将时钟同步到 Spotify 服务器?如果不可能,我必须有哪些选项才能正确同步音乐?我在 Spotify 文档中找不到任何内容,尽管应该是可能的,因为已经有一些现有的应用程序可以做我想做的事情(例如:https://www.kaleidosync.com/)
【问题讨论】:
-
如果没有很多不太实用的 api 调用,我不确定这怎么可能。你能打电话吗,花点时间,在本地计数,定期重新检查以同步你的本地计时器..这有多有效取决于你打算如何处理我猜的进度。
-
是的,我正在尝试这样的东西 :)
标签: spotify clock system-clock