I've properly enabled background audio for my app (in the plist). Playing the next track after the current is complete using SPPlaybackManager in the background (when the phone is locked/off) doesn't work.
When the current track ends, and the audio stops, the app won't begin playing the next track until the phone is unlocked and my app becomes active again.
How do I fix this? Here is a snippet of code I'm using to begin the playing of the next track. I observe that the current track becomes nil, and then begin playing the next track. The log shows me that the next current track is being set in the playback manager object, but it alas is silent.
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if([keyPath isEqualToString:@"spotifyPlaybackManager.currentTrack"]){
NSLog(@"%@ %@",keyPath,self.spotifyPlaybackManager.currentTrack);
if(self.spotifyPlaybackManager.currentTrack==nil && self.mode == PlayerModeSpotify){
NSLog(@"PLAY NEXT");
[self.spotifyPlaybackManager playTrack:self.nextSPTrack callback:^(NSError *error){
if(error) TKLog(@"Spotify Playback Error %@",error);
}];
}
[[NSNotificationCenter defaultCenter] postNotificationName:PlayerNowPlayingItemDidChange object:self];
return;
}
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
Console:
spotifyPlaybackManager.currentTrack (null)
PLAY NEXT
spotifyPlaybackManager.currentTrack <SPTrack: 0x60f8390>: Karaoke