如何与Spotify服务器同步时钟?

问题描述 投票:1回答:1

我正在尝试使用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/

spotify clock system-clock
1个回答
0
投票

似乎目前不可行,因为尽管文档说“ timestamp”字段表示API何时为您提供数据,但由于其方面的某些问题,它实际上不执行它所说的:https://github.com/spotify/web-api/issues/1073

相反,时间戳似乎仅在有新歌曲开始,暂停或搜索时才会改变。这就是说,实际上,我们无法知道何时生成API响应。

© www.soinside.com 2019 - 2024. All rights reserved.