Track
public protocol Track
A type representing a Spotify track.
The Track
protocol serves as the base protocol to which all Spotify track types conform. Its requirements include properties for both simplified
and full
versions of a Spotify track. See the Spotify Web API Object Model for more details.
-
A list of the countries in which the track can be played, identified by their ISO 3166-1 alpha-2 code.
This property may be
nil
if the API request already specified a specific market from which to retrieve the track.Declaration
Swift
var availableMarkets: [String]? { get }
-
The content rating of the track, indicating whether the lyrics are explicit, clean, or unknown.
Declaration
Swift
var contentRating: SKContentRating { get }
-
The disc number (usually
1
unless the album consists of more than one disc).Declaration
Swift
var discNumber: Int { get }
-
The track length in seconds, with millsecond precision.
Declaration
Swift
var duration: TimeInterval { get }
-
Known external URLs for this track.
Declaration
Swift
var externalURLs: [String : URL] { get }
-
The Spotify ID for the track.
Declaration
Swift
var id: String { get }
-
A Boolean value that is available when Track Relinking is applied. If
true
, the track is playable in the given market. Otherwisefalse
.Declaration
Swift
var isPlayable: Bool? { get }
-
The name of the track.
Declaration
Swift
var name: String { get }
-
A URL to a 30-second preview (MP3 format) of the track.
nil
if not available.Declaration
Swift
var previewURL: URL? { get }
-
A value that is available when Track Relinking is applied and is only available if the track linking, in fact, exists (meaning that the requested track has been replaced with a different track). The resource identifiers and locators in the
TrackLink
instance contain information about the originally requested track.Declaration
Swift
var trackLinks: SKTrackLinks? { get }
-
The number of the track. If an album has several discs, the track number is the number on the specified disc.
Declaration
Swift
var trackNumber: Int { get }
-
The Spotify URI for the track.
Declaration
Swift
var uri: String { get }
-
A link to the Web API endpoint providing full details of the track.
Declaration
Swift
var url: URL { get }
-
Known external IDs for the track.
Declaration
Swift
var externalIDs: [String : String]? { get }
-
The popularity of the track. The value will be between 0 and 100, with 100 being the most popular.
The popularity of a track is a value between 0 and 100, with 100 being the most popular. The popularity is calculated by algorithm and is based, in the most part, on the total number of plays the track has had and how recent those plays are.
Generally speaking, songs that are being played a lot now will have a higher popularity than songs that were played a lot in the past. Duplicate tracks (e.g. the same track from a single and an album) are rated independently. Artist and album popularity is derived mathematically from track popularity. Note that the popularity value may lag actual popularity by a few days: the value is not updated in real time.
Declaration
Swift
var popularity: Int? { get }
-
makeAudioFeaturesRequest()
Extension method -
getAudioFeatures(completion:)
Extension methodGets audio feature information for the current track.
Note
This method uses the
SPTAuth
default instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error.Declaration
Swift
public func getAudioFeatures(completion handler: @escaping (SKAudioFeatures?, Error?) -> Void)
Parameters
handler
The callback handler for the request. The parameters for this handler are:
features
: The requested audio features, if available.error
: An error identifying if and why the request failed, ornil
if the request was successful.