我正在使用 javascript API 开发 Spotify 第三方应用程序。 我正在尝试从某个位置播放曲目。 我有以下代码,
player.position = 50000; 播放器.播放(曲目);
但是这段代码从头开始播放曲目。 我想从某个位置播放曲目。 有什么办法可以从某个位置播放曲目吗? 谢谢。
您需要先播放曲目,然后在播放开始后立即寻找您想要的位置。
您可以通过向播放器对象添加
models.EVENT.CHANGE
的观察者并查看 playing
属性来观察播放何时开始。
您还可以通过在 URI 末尾添加
#1:31
来直接链接到曲目中的特定位置,例如 spotify:track:3iDK8BAaBUatPR84gdfa9g#0:15
。
let currentPos = 1500; // in ms
function play() {
let body = {};
body.offset = {};
body.context_uri = "spotify:playlist:" + playlistId; // play playlist
body.offset.position = 0; // selects the first one in the playlist
body.position_ms = currentPos; // in ms
fetchApi("PUT", PLAY_API + "?device_id=" + deviceId, JSON.stringify(body));
}
这是参考https://developer.spotify.com/documentation/web-api/reference/start-a-users-playback