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を作成する方法はありますか?それ以外の場合、メインスレッドで作成されると、しばらくの間実行がブロックされます。