我正在实现一个基于音频的应用程序。我正在使用两个 AVPlayer 播放两种不同的声音。一旦声音播放,我需要做不同的动作。为此,我使用了 NSNotifications。但我的问题是我无法找到与哪个玩家相关的通知。我的通知代码和选择器代码如下,请任何人告诉我我做错了什么。
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playingItemDidEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:iPodPlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playingItemDidEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:applicationPlayer ];
- (void)playingItemDidEnd:(NSNotification *)notification
{
id object= [notification object];
if(object==ipodPlayer)
{
printf("\n Notification from iPod Player ");
}
else if(object==applicationPlayer)
{
printf("\n Notification from application Player ");
}
}
在此先感谢,钱德拉。