diff --git a/SpotifyAPI/Web/SpotifyWebAPI.cs b/SpotifyAPI/Web/SpotifyWebAPI.cs index 3520347d..6704803c 100644 --- a/SpotifyAPI/Web/SpotifyWebAPI.cs +++ b/SpotifyAPI/Web/SpotifyWebAPI.cs @@ -1864,6 +1864,15 @@ namespace SpotifyAPI.Web return DownloadData(_builder.GetDevices()); } + /// + /// Get information about a user’s available devices. + /// + /// + public Task GetDevicesAsync() + { + return DownloadDataAsync(_builder.GetDevices()); + } + /// /// Get information about the user’s current playback state, including track, track progress, and active device. /// @@ -1874,6 +1883,16 @@ namespace SpotifyAPI.Web return DownloadData(_builder.GetPlayback(market)); } + /// + /// Get information about the user’s current playback state, including track, track progress, and active device. + /// + /// An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. + /// + public Task GetPlaybackAsync(string market = "") + { + return DownloadDataAsync(_builder.GetPlayback(market)); + } + /// /// Get the object currently being played on the user’s Spotify account. /// @@ -1884,6 +1903,16 @@ namespace SpotifyAPI.Web return DownloadData(_builder.GetPlayingTrack(market)); } + /// + /// Get the object currently being played on the user’s Spotify account. + /// + /// An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. + /// + public Task GetPlayingTrackAsync(string market = "") + { + return DownloadDataAsync(_builder.GetPlayingTrack(market)); + } + /// /// Transfer playback to a new device and determine if it should start playing. /// @@ -1896,6 +1925,18 @@ namespace SpotifyAPI.Web public ErrorResponse TransferPlayback(string deviceId, bool play = false) => TransferPlayback( new List { deviceId }, play); + /// + /// Transfer playback to a new device and determine if it should start playing. + /// + /// ID of the device on which playback should be started/transferred to + /// + /// true: ensure playback happens on new device. + /// false or not provided: keep the current playback state. + /// + /// + public Task TransferPlaybackAsync(string deviceId, bool play = false) => TransferPlaybackAsync( + new List { deviceId }, play); + /// /// Transfer playback to a new device and determine if it should start playing. /// NOTE: Although an array is accepted, only a single device_id is currently supported. Supplying more than one will return 400 Bad Request @@ -1916,6 +1957,26 @@ namespace SpotifyAPI.Web return UploadData(_builder.TransferPlayback(), ob.ToString(Formatting.None), "PUT"); } + /// + /// Transfer playback to a new device and determine if it should start playing. + /// NOTE: Although an array is accepted, only a single device_id is currently supported. Supplying more than one will return 400 Bad Request + /// + /// A array containing the ID of the device on which playback should be started/transferred. + /// + /// true: ensure playback happens on new device. + /// false or not provided: keep the current playback state. + /// + /// + public Task TransferPlaybackAsync(List deviceIds, bool play = false) + { + JObject ob = new JObject() + { + { "play", play }, + { "device_ids", new JArray(deviceIds) } + }; + return UploadDataAsync(_builder.TransferPlayback(), ob.ToString(Formatting.None), "PUT"); + } + /// /// Start a new context or resume current playback on the user’s active device. /// @@ -1938,6 +1999,28 @@ namespace SpotifyAPI.Web return UploadData(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT"); } + /// + /// Start a new context or resume current playback on the user’s active device. + /// + /// The id of the device this command is targeting. If not supplied, the user's currently active device is the target. + /// Spotify URI of the context to play. + /// A JSON array of the Spotify track URIs to play. + /// Indicates from where in the context playback should start. + /// Only available when context_uri corresponds to an album or playlist object, or when the uris parameter is used. + /// + public Task ResumePlaybackAsync(string deviceId = "", string contextUri = "", List uris = null, + int? offset = null) + { + JObject ob = new JObject(); + if (!string.IsNullOrEmpty(contextUri)) + ob.Add("context_uri", contextUri); + if (uris != null) + ob.Add("uris", new JArray(uris)); + if (offset != null) + ob.Add("offset", new JObject { { "position", offset } }); + return UploadDataAsync(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT"); + } + /// /// Start a new context or resume current playback on the user’s active device. /// @@ -1960,6 +2043,28 @@ namespace SpotifyAPI.Web return UploadData(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT"); } + /// + /// Start a new context or resume current playback on the user’s active device. + /// + /// The id of the device this command is targeting. If not supplied, the user's currently active device is the target. + /// Spotify URI of the context to play. + /// A JSON array of the Spotify track URIs to play. + /// Indicates from where in the context playback should start. + /// Only available when context_uri corresponds to an album or playlist object, or when the uris parameter is used. + /// + public Task ResumePlaybackAsync(string deviceId = "", string contextUri = "", List uris = null, + string offset = "") + { + JObject ob = new JObject(); + if (!string.IsNullOrEmpty(contextUri)) + ob.Add("context_uri", contextUri); + if (uris != null) + ob.Add("uris", new JArray(uris)); + if (!string.IsNullOrEmpty(offset)) + ob.Add("offset", new JObject { { "uri", offset } }); + return UploadDataAsync(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT"); + } + /// /// Pause playback on the user’s account. /// @@ -1970,6 +2075,16 @@ namespace SpotifyAPI.Web return UploadData(_builder.PausePlayback(deviceId), string.Empty, "PUT"); } + /// + /// Pause playback on the user’s account. + /// + /// The id of the device this command is targeting. If not supplied, the user's currently active device is the target. + /// + public Task PausePlaybackAsync(string deviceId = "") + { + return UploadDataAsync(_builder.PausePlayback(deviceId), string.Empty, "PUT"); + } + /// /// Skips to next track in the user’s queue. /// @@ -1980,6 +2095,16 @@ namespace SpotifyAPI.Web return UploadData(_builder.SkipPlaybackToNext(deviceId), string.Empty); } + /// + /// Skips to next track in the user’s queue. + /// + /// The id of the device this command is targeting. If not supplied, the user's currently active device is the target. + /// + public Task SkipPlaybackToNextAsync(string deviceId = "") + { + return UploadDataAsync(_builder.SkipPlaybackToNext(deviceId), string.Empty); + } + /// /// Skips to previous track in the user’s queue. /// Note that this will ALWAYS skip to the previous track, regardless of the current track’s progress. @@ -1992,6 +2117,18 @@ namespace SpotifyAPI.Web return UploadData(_builder.SkipPlaybackToPrevious(deviceId), string.Empty); } + /// + /// Skips to previous track in the user’s queue. + /// Note that this will ALWAYS skip to the previous track, regardless of the current track’s progress. + /// Returning to the start of the current track should be performed using the https://api.spotify.com/v1/me/player/seek endpoint. + /// + /// The id of the device this command is targeting. If not supplied, the user's currently active device is the target. + /// + public Task SkipPlaybackToPreviousAsync(string deviceId = "") + { + return UploadDataAsync(_builder.SkipPlaybackToPrevious(deviceId), string.Empty); + } + /// /// Seeks to the given position in the user’s currently playing track. /// @@ -2004,6 +2141,18 @@ namespace SpotifyAPI.Web return UploadData(_builder.SeekPlayback(positionMs, deviceId), string.Empty, "PUT"); } + /// + /// Seeks to the given position in the user’s currently playing track. + /// + /// The position in milliseconds to seek to. Must be a positive number. + /// Passing in a position that is greater than the length of the track will cause the player to start playing the next song. + /// The id of the device this command is targeting. If not supplied, the user's currently active device is the target. + /// + public Task SeekPlaybackAsync(int positionMs, string deviceId = "") + { + return UploadDataAsync(_builder.SeekPlayback(positionMs, deviceId), string.Empty, "PUT"); + } + /// /// Set the repeat mode for the user’s playback. Options are repeat-track, repeat-context, and off. /// @@ -2015,6 +2164,17 @@ namespace SpotifyAPI.Web return UploadData(_builder.SetRepeatMode(state, deviceId), string.Empty, "PUT"); } + /// + /// Set the repeat mode for the user’s playback. Options are repeat-track, repeat-context, and off. + /// + /// track, context or off. + /// The id of the device this command is targeting. If not supplied, the user's currently active device is the target. + /// + public Task SetRepeatModeAsync(RepeatState state, string deviceId = "") + { + return UploadDataAsync(_builder.SetRepeatMode(state, deviceId), string.Empty, "PUT"); + } + /// /// Set the volume for the user’s current playback device. /// @@ -2026,6 +2186,17 @@ namespace SpotifyAPI.Web return UploadData(_builder.SetVolume(volumePercent, deviceId), string.Empty, "PUT"); } + /// + /// Set the volume for the user’s current playback device. + /// + /// Integer. The volume to set. Must be a value from 0 to 100 inclusive. + /// The id of the device this command is targeting. If not supplied, the user's currently active device is the target. + /// + public Task SetVolumeAsync(int volumePercent, string deviceId = "") + { + return UploadDataAsync(_builder.SetVolume(volumePercent, deviceId), string.Empty, "PUT"); + } + /// /// Toggle shuffle on or off for user’s playback. /// @@ -2037,6 +2208,17 @@ namespace SpotifyAPI.Web return UploadData(_builder.SetShuffle(shuffle, deviceId), string.Empty, "PUT"); } + /// + /// Toggle shuffle on or off for user’s playback. + /// + /// True or False + /// The id of the device this command is targeting. If not supplied, the user's currently active device is the target. + /// + public Task SetShuffleAsync(bool shuffle, string deviceId = "") + { + return UploadDataAsync(_builder.SetShuffle(shuffle, deviceId), string.Empty, "PUT"); + } + #endregion #region Util