From 1b9f66e2d4331c3d55c2232e7a48447bc21b7221 Mon Sep 17 00:00:00 2001 From: Kevin Gysberg Date: Sat, 15 Sep 2018 21:03:29 -0500 Subject: [PATCH] Added position_ms parameter to ResumePlayback. position_ms sets the seek time on the track, whereas offset deals with the song order in a playlist or list of tracks. --- SpotifyAPI.Web/SpotifyWebAPI.cs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/SpotifyAPI.Web/SpotifyWebAPI.cs b/SpotifyAPI.Web/SpotifyWebAPI.cs index e77af2618..657f74f25 100644 --- a/SpotifyAPI.Web/SpotifyWebAPI.cs +++ b/SpotifyAPI.Web/SpotifyWebAPI.cs @@ -2001,11 +2001,12 @@ public Task TransferPlaybackAsync(List deviceIds, bool pl /// 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. + /// Indicates from where in the context playback should start. + /// The starting time to seek the track to /// Only available when context_uri corresponds to an album or playlist object, or when the uris parameter is used. /// public ErrorResponse ResumePlayback(string deviceId = "", string contextUri = "", List uris = null, - int? offset = null) + int? offset = null, int positionMs = 0) { JObject ob = new JObject(); if(!string.IsNullOrEmpty(contextUri)) @@ -2014,6 +2015,8 @@ public ErrorResponse ResumePlayback(string deviceId = "", string contextUri = "" ob.Add("uris", new JArray(uris)); if(offset != null) ob.Add("offset", new JObject { { "position", offset } }); + if (positionMs > 0) + ob.Add("position_ms", positionMs); return UploadData(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT"); } @@ -2023,11 +2026,12 @@ public ErrorResponse ResumePlayback(string deviceId = "", string contextUri = "" /// 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. + /// Indicates from where in the context playback should start. + /// The starting time to seek the track to /// 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) + int? offset = null, int positionMs = 0) { JObject ob = new JObject(); if (!string.IsNullOrEmpty(contextUri)) @@ -2036,6 +2040,8 @@ public Task ResumePlaybackAsync(string deviceId = "", string cont ob.Add("uris", new JArray(uris)); if (offset != null) ob.Add("offset", new JObject { { "position", offset } }); + if (positionMs > 0) + ob.Add("position_ms", positionMs); return UploadDataAsync(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT"); } @@ -2045,11 +2051,12 @@ public Task ResumePlaybackAsync(string deviceId = "", string cont /// 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. + /// Indicates from where in the context playback should start. + /// The starting time to seek the track to /// Only available when context_uri corresponds to an album or playlist object, or when the uris parameter is used. /// public ErrorResponse ResumePlayback(string deviceId = "", string contextUri = "", List uris = null, - string offset = "") + string offset = "", int positionMs = 0) { JObject ob = new JObject(); if (!string.IsNullOrEmpty(contextUri)) @@ -2058,6 +2065,8 @@ public ErrorResponse ResumePlayback(string deviceId = "", string contextUri = "" ob.Add("uris", new JArray(uris)); if (!string.IsNullOrEmpty(offset)) ob.Add("offset", new JObject {{"uri", offset}}); + if (positionMs > 0) + ob.Add("position_ms", positionMs); return UploadData(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT"); } @@ -2067,11 +2076,12 @@ public ErrorResponse ResumePlayback(string deviceId = "", string contextUri = "" /// 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. + /// Indicates from where in the context playback should start. + /// The starting time to seek the track to /// 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 = "") + string offset = "", int positionMs = 0) { JObject ob = new JObject(); if (!string.IsNullOrEmpty(contextUri)) @@ -2080,6 +2090,8 @@ public Task ResumePlaybackAsync(string deviceId = "", string cont ob.Add("uris", new JArray(uris)); if (!string.IsNullOrEmpty(offset)) ob.Add("offset", new JObject { { "uri", offset } }); + if (positionMs > 0) + ob.Add("position_ms", positionMs); return UploadDataAsync(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT"); }