SKPlayer
public struct SKPlayer
A structure used to make requests to the Spotify Web API regarding the current authenticated user’s Spotify player.
-
Creates and returns the request used to get the current authenticated user’s recent tracks.
Declaration
Swift
public static func makeRecentTracksRequest(startAfterDate: Date?, limit: Int?) -> SKRequestParameters
startAfterDateA date after which to request the tracks. The response will include any tracks within the limit that have been played after, but not including, the given date and time, with millisecond precision.
limitThe number of items to return.
Return Value
An
SKRequestinstance with which to perform the API request. -
Creates and returns the request used to get the current authenticated user’s recent tracks.
Declaration
Swift
public static func makeRecentTracksRequest(endBeforeDate: Date?, limit: Int?) -> SKRequestParameters
endBeforeDateA date before which to request the tracks. The response will include any tracks within the limit that have been played up to, but not including, the given date and time, with millisecond precision.
limitThe number of items to return.
Return Value
An
SKRequestinstance with which to perform the API request. -
Gets the current authenticated user’s recently played tracks.
Note
This method uses theSPTAuthdefault instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error. The access token must have been issued on behalf of the current user.Reading the current user’s recently played tracks also requires authorization of the
user-read-recently-playedscope. See Using Scopes for more details.Declaration
Swift
public static func getRecentTracks(after date: Date? = nil, limit: Int? = nil, completion handler: @escaping (CursorPage<SKRecentTrack>?, Error?) -> Void)Parameters
dateA date after which to request the tracks. The response will include any tracks within the limit that have been played after, but not including, the given date and time, with millisecond precision. The default value is
nil, which returns the most recent tracks.limitThe number of items to return. The default value is
nil.handlerThe callback handler for the request. The parameters for this handler are:
tracks: A cursor-based paginated list of recent artists, if any.error: An error identifying if and why the request failed, ornilif the request was successful.
-
Gets the current authenticated user’s recently played tracks.
Note
This method uses theSPTAuthdefault instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error. The access token must have been issued on behalf of the current user.Reading the current user’s recently played tracks also requires authorization of the
user-read-recently-playedscope. See Using Scopes for more details.Declaration
Swift
public static func getRecentTracks(before date: Date?, limit: Int? = nil, completion handler: @escaping (CursorPage<SKRecentTrack>?, Error?) -> Void)Parameters
dateA date before which to request the tracks. The response will include any tracks within the limit that have been played up to, but not including, the given date and time, with millisecond precision.
limitThe number of items to return. The default value is
nil.handlerThe callback handler for the request. The parameters for this handler are:
tracks: A cursor-based paginated list of recent artists, if any.error: An error identifying if and why the request failed, ornilif the request was successful.
-
Gets a list of the current authenticated user’s available devices.
Note
This method uses theSPTAuthdefault instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error. The access token must have been issued on behalf of the current user.Reading the list of the current user’s available devices also requires authorization of the
user-read-playback-statescope. See Using Scopes for more details.Declaration
Swift
public static func getAvailableDevices(completion handler: @escaping ([SKDevice]?, Error?) -> Void)Parameters
handlerThe callback handler for the request. The parameters for this handler are:
devices: An array of available devices, if any.error: An error identifying if and why the request failed, ornilif the request was successful.
-
Creates and returns the request used to get the current authenticated user’s available devices.
Declaration
Swift
public static func makePlaybackStateRequest(locale: Locale?) -> SKRequestParameters
localeThe locale-specific storefront/market from which to request.
Return Value
An
SKRequestinstance with which to perform the API request. -
Gets the active Spotify player’s current playback state, including the currently playing track if applicable.
Note
This method uses theSPTAuthdefault instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error. The access token must have been issued on behalf of the current user.Reading the current Spotify player’s playback information also requires authorization of the
user-read-playback-statescope. See Using Scopes for more details.Declaration
Swift
public static func getPlaybackState(for locale: Locale? = SKCatalog.local.locale, completion handler: @escaping (SKPlaybackState?, Error?) -> Void)Parameters
localeThe locale-specific storefront/market from which to request. The default value is the locale for the shared
SKCataloginstance, which by default represents the user’s region settings at the time the method is called.handlerThe callback handler for the request. The parameters for this handler are:
state: AnSKPlaybackStateinstance.error: An error identifying if and why the request failed, ornilif the request was successful.
-
Creates and returns the request used to transfer playback to another device.
Declaration
Swift
public static func makeTransferRequest(deviceID: String, forcePlayback: Bool) -> SKRequestParameters
deviceIDThe ID of the device on which playback should be transferred.
forcePlaybackA Boolean value indicating whether the new device should begin playback:
trueensures playback happens on the new device;falsekeeps the current playback state. Note that providingfalsewill not pause playback.Return Value
An
SKRequestinstance with which to perform the API request. -
Transfers playback to the given device.
Important
The given
SKDeviceinstance must have an ID. If the device contains anilID value, then this method will immediately call the handler and provide anSKErrorinstance denoting a bad request.Note
This method uses the
SPTAuthdefault instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error. The access token must have been issued on behalf of the current user.Modifying the playback state, to include the active device, also requires authorization of the
user-modify-playback-statescope. See Using Scopes for more details.Declaration
Swift
public static func transfer(to device: SKDevice, forcingPlayback forcePlayback: Bool = false, completion handler: @escaping SKErrorHandler)Parameters
deviceThe device on which playback should be transferred.
forcePlaybackA Boolean value indicating whether the new device should begin playback:
trueensures playback happens on the new device;falsekeeps the current playback state. The default value isfalse. Note that providingfalsewill not pause playback.handlerThe callback handler for the request, providing an error identifying if and why the request failed, or
nilif the request was successful.
View on GitHub
SKPlayer Structure Reference