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?否則,如果它是在主線程上創建的,它會暫時阻止執行。
我有同樣的問題 – Slavik 2012-01-13 06:13:40