iphone - 如果 iPod 音乐播放器是在后台创建的,则它不会发送通知

标签 iphone multithreading mpmusicplayercontroller

如果 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/

相关文章:

javascript - 在移动网络应用程序上触发滑动和触摸事件? - iPhone/安卓

python - 如何在 Scrapy/Twisted 中使用线程,即如何在响应回调中对阻塞代码进行异步调用?

Python 关闭线程服务器中的套接字和连接?

ios - 在 iOS 11 中播放音乐库时更改和隐藏音量 HUD(音量叠加)

iphone - 如何创建同步版本的 NSURLConnection

iphone - iOS SLComposeViewController - 不显示推特帖子的网址

iphone - 在MKMapView中找到地址

c - 多线程素数生成器

ios - EXC_BAD_ACCESS 和 MPMusicPlayerController

ios - 无法设置 MPMusicPlayerController.shuffleMode