Skip to content

Commit 81fe176

Browse files
kg73JohnnyCrazy
authored andcommitted
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. (JohnnyCrazy#288)
1 parent 5e134df commit 81fe176

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

‎SpotifyAPI.Web/SpotifyWebAPI.cs‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,11 +2001,12 @@ public Task<ErrorResponse> TransferPlaybackAsync(List<string> deviceIds, bool pl
20012001
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param>
20022002
/// <param name="contextUri">Spotify URI of the context to play.</param>
20032003
/// <param name="uris">A JSON array of the Spotify track URIs to play.</param>
2004-
/// <param name="offset">Indicates from where in the context playback should start.
2004+
/// <param name="offset">Indicates from where in the context playback should start.
2005+
/// <param name="positionMs">The starting time to seek the track to</param>
20052006
/// Only available when context_uri corresponds to an album or playlist object, or when the uris parameter is used.</param>
20062007
/// <returns></returns>
20072008
public ErrorResponse ResumePlayback(string deviceId = "", string contextUri = "", List<string> uris = null,
2008-
int? offset = null)
2009+
int? offset = null, int positionMs = 0)
20092010
{
20102011
JObject ob = new JObject();
20112012
if(!string.IsNullOrEmpty(contextUri))
@@ -2014,6 +2015,8 @@ public ErrorResponse ResumePlayback(string deviceId = "", string contextUri = ""
20142015
ob.Add("uris", new JArray(uris));
20152016
if(offset != null)
20162017
ob.Add("offset", new JObject { { "position", offset } });
2018+
if (positionMs > 0)
2019+
ob.Add("position_ms", positionMs);
20172020
return UploadData<ErrorResponse>(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT");
20182021
}
20192022

@@ -2023,11 +2026,12 @@ public ErrorResponse ResumePlayback(string deviceId = "", string contextUri = ""
20232026
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param>
20242027
/// <param name="contextUri">Spotify URI of the context to play.</param>
20252028
/// <param name="uris">A JSON array of the Spotify track URIs to play.</param>
2026-
/// <param name="offset">Indicates from where in the context playback should start.
2029+
/// <param name="offset">Indicates from where in the context playback should start.
2030+
/// <param name="positionMs">The starting time to seek the track to</param>
20272031
/// Only available when context_uri corresponds to an album or playlist object, or when the uris parameter is used.</param>
20282032
/// <returns></returns>
20292033
public Task<ErrorResponse> ResumePlaybackAsync(string deviceId = "", string contextUri = "", List<string> uris = null,
2030-
int? offset = null)
2034+
int? offset = null, int positionMs = 0)
20312035
{
20322036
JObject ob = new JObject();
20332037
if (!string.IsNullOrEmpty(contextUri))
@@ -2036,6 +2040,8 @@ public Task<ErrorResponse> ResumePlaybackAsync(string deviceId = "", string cont
20362040
ob.Add("uris", new JArray(uris));
20372041
if (offset != null)
20382042
ob.Add("offset", new JObject { { "position", offset } });
2043+
if (positionMs > 0)
2044+
ob.Add("position_ms", positionMs);
20392045
return UploadDataAsync<ErrorResponse>(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT");
20402046
}
20412047

@@ -2045,11 +2051,12 @@ public Task<ErrorResponse> ResumePlaybackAsync(string deviceId = "", string cont
20452051
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param>
20462052
/// <param name="contextUri">Spotify URI of the context to play.</param>
20472053
/// <param name="uris">A JSON array of the Spotify track URIs to play.</param>
2048-
/// <param name="offset">Indicates from where in the context playback should start.
2054+
/// <param name="offset">Indicates from where in the context playback should start.
2055+
/// <param name="positionMs">The starting time to seek the track to</param>
20492056
/// Only available when context_uri corresponds to an album or playlist object, or when the uris parameter is used.</param>
20502057
/// <returns></returns>
20512058
public ErrorResponse ResumePlayback(string deviceId = "", string contextUri = "", List<string> uris = null,
2052-
string offset = "")
2059+
string offset = "", int positionMs = 0)
20532060
{
20542061
JObject ob = new JObject();
20552062
if (!string.IsNullOrEmpty(contextUri))
@@ -2058,6 +2065,8 @@ public ErrorResponse ResumePlayback(string deviceId = "", string contextUri = ""
20582065
ob.Add("uris", new JArray(uris));
20592066
if (!string.IsNullOrEmpty(offset))
20602067
ob.Add("offset", new JObject {{"uri", offset}});
2068+
if (positionMs > 0)
2069+
ob.Add("position_ms", positionMs);
20612070
return UploadData<ErrorResponse>(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT");
20622071
}
20632072

@@ -2067,11 +2076,12 @@ public ErrorResponse ResumePlayback(string deviceId = "", string contextUri = ""
20672076
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param>
20682077
/// <param name="contextUri">Spotify URI of the context to play.</param>
20692078
/// <param name="uris">A JSON array of the Spotify track URIs to play.</param>
2070-
/// <param name="offset">Indicates from where in the context playback should start.
2079+
/// <param name="offset">Indicates from where in the context playback should start.
2080+
/// <param name="positionMs">The starting time to seek the track to</param>
20712081
/// Only available when context_uri corresponds to an album or playlist object, or when the uris parameter is used.</param>
20722082
/// <returns></returns>
20732083
public Task<ErrorResponse> ResumePlaybackAsync(string deviceId = "", string contextUri = "", List<string> uris = null,
2074-
string offset = "")
2084+
string offset = "", int positionMs = 0)
20752085
{
20762086
JObject ob = new JObject();
20772087
if (!string.IsNullOrEmpty(contextUri))
@@ -2080,6 +2090,8 @@ public Task<ErrorResponse> ResumePlaybackAsync(string deviceId = "", string cont
20802090
ob.Add("uris", new JArray(uris));
20812091
if (!string.IsNullOrEmpty(offset))
20822092
ob.Add("offset", new JObject { { "uri", offset } });
2093+
if (positionMs > 0)
2094+
ob.Add("position_ms", positionMs);
20832095
return UploadDataAsync<ErrorResponse>(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT");
20842096
}
20852097

0 commit comments

Comments
 (0)