带参数的 NSNotificationCenter

发布于 2024-11-27 05:18:41 字数 1093 浏览 4 评论 0原文

我正在实现一个基于音频的应用程序。我使用两个 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 ");
     }

}

提前致谢, 钱德拉。

I am implementing an Audio based application. In that I am playing two different sounds using two AVPlayers. I need to do different actions once the sounds played. For this I used NSNotifications. But my problem is I am not able to find the Notifications related to which player. My notifications code and selector code is as follows please any one suggest me what the mistake I did.

[[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 ");
     }

}

Thanks in advance,
Chandra.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期情话 2024-12-04 05:18:41

我需要更改代码库如下,

   [[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])
    {

    }
}

I need to change the code base as follows,

   [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playingItemDidEnd:)
                                             name:AVPlayerItemDidPlayToEndTimeNotification
                                           object:[applicationPlayer currentItem] ];

   [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playingItemDidEnd:)
                                             name:AVPlayerItemDidPlayToEndTimeNotification
                                           object:[iPodPlayer currentItem]];

And selector code should be as follows,

- (void)playingItemDidEnd:(NSNotification *)notification 
{

    AVPlayerItem* object= [notification object];
    if(object==[applicationPlayer currentItem])
    {

    }
    else if(object==[avPlayer currentItem])
    {

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文