Si iPodMusicPlayer est créé en arrière-plan, je n'envoie pas de notifications sur les changements d'état de lecture.iPodMusicPlayer n'envoie pas de notifications s'il a été créé en arrière-plan
Voici le 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];
}
Est-il possible comment créer iPodMusicPlayer en arrière-plan? Sinon, s'il est créé sur le thread principal, il bloque les exécutions pendant un certain temps.
J'ai le même problème – Slavik