user25093
user25093

Reputation: 287

How to get Spotify iOS currently playing track

I'm using SPTAudioStreamingController.sharedInstance().metadata.currentTrack?.uri to get the currently playing track, but sometimes it returns the next song on the playlist, instead of what is playing right now.

Edit: I think it may have to do with the playlist it is playing from, since whenever I skip a track, it deletes from the playlist. Is there a way to play from the top song in the playlist every time a skip occurs?

Or even better: Is there a way to refresh a playlist?

Upvotes: 0

Views: 617

Answers (1)

Alex Harris
Alex Harris

Reputation: 6402

You can use a delegate method and locally keep track of what track is playing:

func audioStreaming(_ audioStreaming: SPTAudioStreamingController!, didStartPlayingTrack trackUri: String!) {
  self.currentURI = trackURI
}

Whenever a track starts playing, the delegate method will fire and you can locally store the current URI. Just make sure to also utilize the other delegate methods like didStopPlayingTrack in order to ensure you have all the correct information.

Upvotes: 1

Related Questions