I'm looking for a solution that controls play, pause and forward music players such as Google Play or Spotify apps. Following code works fine for default music app to play/pause music:
iPodMusicPlayer = [MPMusicPlayerController iPodMusicPlayer];
if ([iPodMusicPlayer playbackState] == MPMusicPlaybackStatePlaying) {
NSLog(@"Pause music");
[iPodMusicPlayer pause];
}
else if ([iPodMusicPlayer playbackState] == MPMusicPlaybackStatePaused){
NSLog(@"Play music");
[iPodMusicPlayer play];
}
And to forward next song:
[iPodMusicPlayer skipToNextItem];
Is there any way to do the same with other Music Players?
I have tried next code but with not success:
bool active = [[AVAudioSession sharedInstance] isOtherAudioPlaying];
if (active) {
[[AVAudioSession sharedInstance] setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
}
else{
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
}