IPodMusicPlayer does not send notifications if created in the background

If the iPodMusicPlayer is created in the background, I do not send notifications about changes to the playback state.

Here is the 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 a way to create an iPodMusicPlayer in the background? Otherwise, if created on the main thread, it will block execution for a while.

+2


a source to share


1 answer


+2


a source







All Articles