iPodMusicPlayer doesn't send notifications, if it is created in background

Posted by Aleksejs on Stack Overflow See other posts from Stack Overflow or by Aleksejs
Published on 2010-05-04T18:20:52Z Indexed on 2010/05/04 18:58 UTC
Read the original article Hit count: 184

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.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about mpmusicplayercontroller