iPhone:“结束中断”没有为调用班级

发布于 2024-10-14 07:23:33 字数 803 浏览 2 评论 0原文

我有一个实现 AVAudioSessionDelegate 协议的声音管理器类,即 beginInterruption 和 endInterruption 方法。

但是,当我拨打电话并返回应用程序时,这两种方法都不会被调用,并且应用程序随后将保持沉默。这是使用调试器和 NSLog 调用进行测试的。

声音管理器类使用 openAL。

-

我的类声明如下:

@interface CMOpenALSoundManager : NSObject <AVAudioPlayerDelegate, AVAudioSessionDelegate> 

委托实现如下:

- (void)beginInterruption {
    [self setActivated:NO];
}
- (void)audioPlayerBeginInterruption {
    [self setActivated:NO];
}

- (void)endInterruption {
    [self setActivated:YES];
}
- (void)audioPlayerEndInterruption {
    [self setActivated:YES];
}

其中 setActivated:(BOOL)state 包含启动和停止声音管理器的代码。

-

我看不出有任何理由不调用委托方法 - 也许当我启动声音管理器或设置音频属性等时我忘记做一些事情?

或者我公然错过了一些更明显的东西:o

任何想法都非常感谢!

I have a sound manager class that implements the AVAudioSessionDelegate protocol, i.e. the beginInterruption and endInterruption methods.

However, when I ring the phone and go back to the app, neither method gets called and the app is thereafter silent. This is tested using both the debugger and using NSLog calls.

The sound manager class uses openAL.

-

My class is declared like so:

@interface CMOpenALSoundManager : NSObject <AVAudioPlayerDelegate, AVAudioSessionDelegate> 

and the delegate implementations are as follows:

- (void)beginInterruption {
    [self setActivated:NO];
}
- (void)audioPlayerBeginInterruption {
    [self setActivated:NO];
}

- (void)endInterruption {
    [self setActivated:YES];
}
- (void)audioPlayerEndInterruption {
    [self setActivated:YES];
}

where setActivated:(BOOL)state contains the code to start and stop the sound manager.

-

I can't see any reason for the delegate methods not to be called - perhaps is there something I am forgetting to do when I start up the sound manager or set the audio properties etc?

Or am I blatantly missing something more obvious :o

Any ideas are much appreciated!

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

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

发布评论

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

评论(1

吃→可爱长大的 2024-10-21 07:23:33

这似乎是 iOS 中的一个错误。在多种情况下,endInterruption 回调不会被调用。我所做的是检查另一个应用程序当前是否正在我的 applicationWillEnterForeground 方法中播放音频(或者准确地说:我已经注册了相应的通知,因此我不必在应用程序委托)。您可以通过 AudioSessionGetPropertykAudioSessionProperty_OtherAudioIsPlaying

This seems to be a bug in iOS. There are various conditions in which the endInterruption callback is not called. What I've done is to check whether another app is currently playing audio in my applicationWillEnterForeground method (or to be precise: I've registered to the corresponding notification so I don't have to do it in the app delegate). You can check that via AudioSessionGetProperty and kAudioSessionProperty_OtherAudioIsPlaying.

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