如果 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 吗?否则,如果它是在主线程上创建的,它会阻塞执行一段时间。
最佳答案
关于iphone - 如果 iPod 音乐播放器是在后台创建的,则它不会发送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2767909/