If iPodMusicPlayer is created in background, then I doesn't send notifications about playback state changes.
Here is code:
- (void)initMusicPlayer {
musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:@selector(musicPlayerStateChanged:)
name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification
object:musicPlayer];
[notificationCenter addObserver:self selector:@selector(musicPlayerStateChanged:)
name:MPMusicPlayerControllerPlaybackStateDidChangeNotification
object:musicPlayer];
[musicPlayer beginGeneratingPlaybackNotifications];
}
- (void)viewDidLoad {
[self performSelectorInBackground:@selector(initMusicPlayer) withObject:nil];
}
Is there some way how to create iPodMusicPlayer in background? Otherwise if it is created on the main thread, it blocks executions for a while.