Spotify API-Net ResumePlayback - 文档中的代码示例出错

Spotify API-Net ResumePlayback - Error With Code Example From Documentation

Spotiy API_NET 上 ResumePlayback

的文档

给出以下例子:

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

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

Error CS0121 The call is ambiguous between the following methods or properties: 'SpotifyWebAPI.ResumePlayback(string, string, List, int?)' and 'SpotifyWebAPI.ResumePlayback(string, string, List, string)' Can anyone tell me what is wrong with this?

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

编辑

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

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

_spotify.ResumePlayback(offset: "")

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(也就是第三个参数)。它将采用其他参数的默认值。对于这两种方法,这些默认值(对于字符串或 Nullable (int?) 为 null)适用,因此编译器无法决定它应该绑定到哪个方法。它向您显示一个错误。

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

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)