如果在后台创建了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吗?否则,如果它是在主线程上创建的,它会阻止执行一段时间。