Question

I'm integrating the Spotify iOS SDK into an app. How can I listen for track ending events on the SPTAudioStreamingController or SPTTrackPlayer?

I'm cool with playing, pausing, authenticating, etc. I just need to grab a track-ended event.

I can see the SPTTrackPlayerDelegate has methods, most appropriately, trackPlayer:didEndPlaybackOfTrackAtIndex:ofProvider,

but how can I use these? Is there any examples of usage?

Was it helpful?

Solution

These classes follow the standard Cocoa delegate pattern.

First, set yourself as the delegate on your track player:

self.trackPlayer.delegate = self;

Then implement the delegate method in whatever self is:

-(void)trackPlayer:(SPTTrackPlayer *)player didEndPlaybackOfTrackAtIndex:(NSInteger)index ofProvider:(id<SPTTrackProvider>)provider {
    // Track playback ended.
}

Your delegate method will then be called by the track player when appropriate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top