Ios4 带参数的NSNotificationCenter
我正在实现一个基于音频的应用程序。我用两个AVP播放器播放两种不同的声音。一旦声音响起,我需要做不同的动作。为此,我使用了通知。但我的问题是我无法找到与哪个玩家相关的通知。我的通知代码和选择器代码如下,请任何人告诉我我犯了什么错误Ios4 带参数的NSNotificationCenter,ios4,nsnotifications,nsnotificationcenter,Ios4,Nsnotifications,Nsnotificationcenter,我正在实现一个基于音频的应用程序。我用两个AVP播放器播放两种不同的声音。一旦声音响起,我需要做不同的动作。为此,我使用了通知。但我的问题是我无法找到与哪个玩家相关的通知。我的通知代码和选择器代码如下,请任何人告诉我我犯了什么错误 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playingItemDidEnd:)
[[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 ");
}
}
提前感谢,,
Chandra.我需要如下更改代码库
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playingItemDidEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[applicationPlayer currentItem] ];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playingItemDidEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[iPodPlayer currentItem]];
- (void)playingItemDidEnd:(NSNotification *)notification
{
AVPlayerItem* object= [notification object];
if(object==[applicationPlayer currentItem])
{
}
else if(object==[avPlayer currentItem])
{
}
}
和选择器代码应如下所示
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playingItemDidEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[applicationPlayer currentItem] ];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playingItemDidEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[iPodPlayer currentItem]];
- (void)playingItemDidEnd:(NSNotification *)notification
{
AVPlayerItem* object= [notification object];
if(object==[applicationPlayer currentItem])
{
}
else if(object==[avPlayer currentItem])
{
}
}
我需要如下更改代码库:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playingItemDidEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[applicationPlayer currentItem] ];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playingItemDidEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[iPodPlayer currentItem]];
- (void)playingItemDidEnd:(NSNotification *)notification
{
AVPlayerItem* object= [notification object];
if(object==[applicationPlayer currentItem])
{
}
else if(object==[avPlayer currentItem])
{
}
}
和选择器代码应如下所示
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playingItemDidEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[applicationPlayer currentItem] ];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playingItemDidEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[iPodPlayer currentItem]];
- (void)playingItemDidEnd:(NSNotification *)notification
{
AVPlayerItem* object= [notification object];
if(object==[applicationPlayer currentItem])
{
}
else if(object==[avPlayer currentItem])
{
}
}