May be a simple question, but I am trying to use Spotify's API which is documented in Objective C but I have been working on it in Swift as far as I can.
@property (nonatomic, readonly, copy) NSArray *genres is one of their API protocols for the SPTartist class, however; I can't figure out how to use it in a working manner in swift.
Here is example code of something I have gotten to work.
func updateTrackLength(){
if player?.currentTrackMetadata == nil {
trackLength.text = ""
return
}
let length = player?.currentTrackMetadata[SPTAudioStreamingMetadataTrackDuration] as Int
let convert = length / 60
let remainder = length % 60
var newlength = String(convert)
var newRemainder = String(remainder)
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.trackLength.text = "Track length: " + newlength + " Minutes " + newRemainder + " Seconds"
})
}
This uses the currentTrackMetaData and whatever SPT protocol to track the string output. When I try using SPTArtistGenres or SPTArtistGenre in place of SPTAudioStreamingMetaDataTrackDuration, it does not work. To specify my question, I want to use the currentTrackMetaData to call the genres property up above. Any advice is greatly appreciated!
This has absolutely nothing to do with Swift - if you tried to do what you're doing in Objective-C it'd fail as well.
The player's
currentTrackMetadatadictionary returns bare URLs - if you justprintln()the response toplayer.currentTrackMetadata, you'll see that it contains nothing but URLs.The
genresproperty is on theSPTArtistclass. To convert your bare URL into anSPTArtist, use theSPTRequestclass (specifically, therequestItemAtURImethod). Once you have anSPTArtistobject, you'll be able to get all the metadata you need from it, including genres.Please see the documentation shipped with the library for details. In addition, the Simple Player demo app included with the SDK does a similar thing.