【问题标题】:Set Spotify playing position设置 Spotify 播放位置
【发布时间】:2018-03-12 19:58:33
【问题描述】:

我正在使用来自 JohnnyCrazy 的 GitHub 上的 SpotifyAPI-NET 在我的 Spotify 桌面客户端上播放和暂停歌曲。这很好用。

现在我想改变当前播放歌曲的播放位置。所以我只想说“SetPlayingPosition(64)”之类的东西来从位置“01:04”播放当前歌曲。 SpotifyLocalAPI 似乎不支持此功能。

要播放和暂停歌曲,API 使用以下格式的消息: http://127.0.0.1:4381/remote/pause.json?pause=true&ref=&cors=&_=1520448230&oauth=oauth&csrf=csrf

我试图找到这种格式的可能命令的摘要,但我什么也没找到。

有没有像http://127.0.0.1:4381/remote/seek.json...这样的东西可以用来寻找特定的位置?

编辑:

我尝试在 SpotifyAPI 的本地部分的 RemoteHandler 类中编写自己的方法。使用这种方法,我可以在当前播放中设置位置。 这是我的代码:

internal async Task SendPositionRequest(double playingPositionSec)   //The desired playback position in seconds
{
    StatusResponse status = GetNewStatus();  //Get the current status of the local desktop API

    string trackUri = "spotify:track:" + status.Track.TrackResource.ParseUri().Id;  //The URI of the current track

    TimeSpan playingPositionTimeSpan = TimeSpan.FromSeconds(playingPositionSec);
    string playingPosStr = playingPositionTimeSpan.ToString(@"mm\:ss");   //Convert the playingPosition to a string (Format mm:ss)

    string playingContext = "spotify:artist:1EfwyuCzDQpCslZc8C9gkG";

    await SendPlayRequest(trackUri + "#" + playingPosStr, playingContext);
    if (!status.Playing) { await SendPauseRequest(); }
}

我需要使用正确的播放上下文调用 SendPlayRequest() 方法,因为当当前歌曲是播放列表的一部分并且您在没有上下文的情况下调用 SendPlayRequest() 时,下一首歌曲不再来自播放列表。

但是你可以看到我现在使用的是固定的上下文。

所以我现在的问题是:如何使用 SpotifyLocalAPI 获取当前播放歌曲的上下文(播放列表、艺术家等)?

【问题讨论】:

    标签: spotify


    【解决方案1】:

    您提到的库的SeekPlayback 方法可让您在用户正在收听的任何设备上搜索播放。你可以找到文档here

    目前无法使用该库的 Spotify Local API 部分进行播放。

    【讨论】:

    • 谢谢,但当我在“SpotifyWebAPI”中使用“SeekPlayback”方法时出现以下错误:错误 403 -“当前用户不可用”我没有 Spotify Premium。 “SpotifyLocalAPI”有这样的方法吗?
    • 看起来该方法在 SpotifyLocalAPI 上不可用。您可以通过the project issue tracker 向开发者提交功能请求。我会更新我的答案以澄清。
    • 我在 GitHub 上打开了一个问题,JohnnyCrazy 回答说“本地 API 不可能”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多