I added a Spotify player to my application, which also plays music using MPMusicPlayerController. When music is played from Spotify and the screen is locked, remote control events are not accepted for play / pause and FFW / RWD when the user presses these buttons on the locked screen.
If music plays from MPMusicPlayerController, I can receive remote control events based on the following code:
-(void) ViewDidLoad { ... [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; [self becomeFirstResponder]; ... }
and
- (BOOL) canBecomeFirstResponder { return YES; } - (void) remoteControlReceivedWithEvent: (UIEvent*) event { // see [event subtype] for details if (event.type == UIEventTypeRemoteControl) { // We may be receiving an event from the lockscreen switch (event.subtype) { case UIEventSubtypeRemoteControlTogglePlayPause: case UIEventSubtypeRemoteControlPlay: case UIEventSubtypeRemoteControlPause: // User pressed play or pause from lockscreen [self playOrPauseMusic:nil]; break; case UIEventSubtypeRemoteControlNextTrack: // User pressed FFW from lockscreen [self fastForwardMusic:nil]; break; case UIEventSubtypeRemoteControlPreviousTrack: // User pressed rewind from lockscreen [self rewindMusic:nil]; break; default: break; } } }
While iPod controls are visible when the app enters the background, they donβt respond when I pause. Instead, the iPod controls disappear when I pause. What add-on is needed to detect play / pause and FFW / RWD when streaming audio, such as Spotify, in the background from the lock screen?
source share