Jor*_*ith 2 iphone audio openal objective-c
我有一个声音管理器类,它实现了AVAudioSessionDelegate协议,即beginInterruption和endInterruption方法.
但是,当我给手机打电话并回到应用程序时,这两种方法都没有被调用,应用程序此后也是静音.这是使用调试器和使用NSLog调用进行测试的.
声音管理器类使用openAL.
-
我的类声明如下:
@interface CMOpenALSoundManager : NSObject <AVAudioPlayerDelegate, AVAudioSessionDelegate>
Run Code Online (Sandbox Code Playgroud)
并且委托实现如下:
- (void)beginInterruption {
[self setActivated:NO];
}
- (void)audioPlayerBeginInterruption {
[self setActivated:NO];
}
- (void)endInterruption {
[self setActivated:YES];
}
- (void)audioPlayerEndInterruption {
[self setActivated:YES];
}
Run Code Online (Sandbox Code Playgroud)
其中setActivated:(BOOL)状态包含启动和停止声音管理器的代码.
-
我看不出任何不能调用委托方法的原因 - 也许在我启动声音管理器或设置音频属性等时我忘了做什么?
或者我公然错过了一些更明显的东西:o
任何想法都非常感谢!
这似乎是iOS中的一个错误.有各种endInterruption不调用回调的条件.我所做的是检查另一个应用程序当前是否正在我的applicationWillEnterForeground方法中播放音频(或者确切地说:我已注册到相应的通知,因此我不必在应用程序委托中执行此操作).您可以通过AudioSessionGetProperty和kAudioSessionProperty_OtherAudioIsPlaying进行检查.