问题是我有三个NSNotificationcenter的设置来侦听用户更改歌曲,音量和播放列表。该应用可以正常播放来自播放列表用户选择的歌曲。NSNotification not calling
当用户选择要播放的歌曲时,通常会注册用户操作来播放歌曲并更改播放状态,但有时不会这样做。创建一个只允许玩和不停止的连续循环。 (基本上,代码存在间歇性故障。)
我相信问题是来自一个操作的NSNotificationcenter调用被另一个NSNotificationcenter调用覆盖。取消另一个呼叫。从而使用户无法停止播放歌曲。
应用功能:允许用户从PickerView中选择播放列表,从播放列表中加载歌曲并允许用户从TableView中选择歌曲进行播放。对于implentation +头
- (void)addMusicPlayerObserver {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleNowPlayingSongStateChanged:)
name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification
object:self.musicPlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handlePlaybackStateChanged:)
name:MPMusicPlayerControllerPlaybackStateDidChangeNotification
object:self.musicPlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleVolumeChangedFromOutSideApp:)
name:MPMusicPlayerControllerVolumeDidChangeNotification
object:self.musicPlayer];
[self.musicPlayer beginGeneratingPlaybackNotifications];
}
- (void)removeMusicPlayerObserver {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification
object:self.musicPlayer];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMusicPlayerControllerPlaybackStateDidChangeNotification
object:self.musicPlayer];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMusicPlayerControllerVolumeDidChangeNotification
object:self.musicPlayer];
[self.musicPlayer endGeneratingPlaybackNotifications];
}
的完整代码
任何帮助将是巨大的。
只是小小的一点,'viewDidunload'不会在iOS6或Higer中调用。在'viewWillAppear' /'viewDidDisappear'中添加和删除观察者。 – rckoenes
干杯。错过了viewDidUnload不在iOS 6中:/将移动添加/删除观察者到viewWillAppear/viewDidDisappear :) – Evilelement
也尝试删除'NSNotificationCenter'的'object'参数'self.musicPlayer'并检查它是否工作然后。 – rckoenes