【问题标题】:Spotify API-Net ResumePlayback - Error With Code Example From DocumentationSpotify API-Net ResumePlayback - 文档中的代码示例错误
【发布时间】:2019-01-22 16:18:54
【问题描述】:

ResumePlayback 的 Spitiy API_NET 文档

举个例子:

ErrorResponse error = _spotify.ResumePlayback(uris: new List<string> { "spotify:track:4iV5W9uYEdYUVa79Axb7Rh" });

当我在 C# 中尝试该代码时,我收到以下代码错误,导致我无法构建:

错误 CS0121 调用在以下方法或属性之间不明确:'SpotifyWebAPI.ResumePlayback(string, string, List, int?)' 和 'SpotifyWebAPI.ResumePlayback(string, string, List, string)' 谁能告诉我这是怎么回事?

另外,在暂停点恢复现有播放器的最简单方法是什么?

编辑

@rene 回答了我问题的第一部分。

关于第二部分,如何在暂停点恢复现有播放器,我通过图书馆的Github站点得到了答案,很简单:

_spotify.ResumePlayback(offset: "")

【问题讨论】:

    标签: spotify spotify-desktop


    【解决方案1】:

    ResumePlayback 方法有两个采用这些参数的重载:

    ErrorResponse ResumePlayback(string deviceId = "", 
                                string contextUri = "", 
                                List<string> uris = null,
                                int? offset = null)
    

    ErrorResponse ResumePlayback(string deviceId = "", 
                                 string contextUri = "", 
                                 List<string> uris = null,
                                 string offset = "")
    

    当编译器遇到这一行时

    ErrorResponse error = _spotify.ResumePlayback(
                                uris: new List<string> { "spotify:track:4iV5W9uYEdYUVa79Axb7Rh" });
    

    它必须决定要调用哪个 ResumePlayback,它不想猜测或掷骰子。

    它查看将提供哪些参数,您只给它uris(即第三个参数)。它将假定其他参数的默认值。对于这两种方法,这些默认值(字符串为 null 或 Nullable (int?))都适用,因此编译器无法决定它应该绑定到哪个方法。它向您显示一个错误。

    提供更多参数,以便编译器可以选择唯一的重载。

    ErrorResponse error = _spotify.ResumePlayback(
                                uris: new List<string> { "spotify:track:4iV5W9uYEdYUVa79Axb7Rh" }
                                , 
                                offset: 0
                           );
    

    添加该命名参数 offset 并将其设置为 int 值 0 足以让编译器选择此重载进行绑定:

    ResumePlayback(string deviceId, string contextUri, List<string> uris, int? offset)
    

    【讨论】:

    • 好的,我明白了,但我认为最终的偏移参数也是可选的;显然,文档中提供的示例中存在错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-24
    相关资源
    最近更新 更多