2010-05-04 34 views
2

如果在後臺創建iPodMusicPlayer,則不會發送有關播放狀態更改的通知。如果iPodMusicPlayer在後臺創建,它不會發送通知

這裏是代碼:

- (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]; 
} 

是否有某種方式如何在後臺創建iPodMusicPlayer?否則,如果它是在主線程上創建的,它會暫時阻止執行。

+0

我有同樣的問題 – Slavik 2012-01-13 06:13:40

回答

相關問題