使用视频/摄像机时未触发AVAudioSessionInterruptionNotification [英] AVAudioSessionInterruptionNotification not fired when Video/Camera is used
问题描述
我有一些SIP应用程序.直到我只使用音频,evrything才能正常工作之前,在必要时我会收到AVAudioSessionInterruptionNotification
.
I have some SIP application. Until I've used audio only evrything was working correctly, I was receiving AVAudioSessionInterruptionNotification
when it was necessary.
使用视频时(接收和发送摄像机供稿)出现问题.一旦我将会话与视频一起使用,就不会再触发通知,即使仅使用以后的音频也是如此.
Problem appeared when video was used (receiving and sending camera feed). Once I use session with video, notification is never fired again, even if later audio is used only.
我该如何解决?我发现了类似的主题,但是答案只是提示,我还没有完全理解.另外,我没有相机/捕获设备"和"AVCaptureSession",因为音频和视频流是由封闭的第三方库提供的,但是我的代码必须处理中断.
How can I fix that? I've found similar topic, but answer is to prompt and I don't fully get it. Also I do not have "camera/capture device" and "AVCaptureSession" since audio and video streaming is provided by closed third party library, but my code have to handle interruptions.
是否必须更改某些属性以使此通知始终被触发(建议链接的主题),还是应该使用替代通知.
我正在研究文档,但是找不到任何对我有用的东西.
Do I have to change some property to have this notification always fired (linked topic suggest that), or should I use alternative notification.
I was digging in documentation but I've failed to find anything useful for me.
我尝试使用AVCaptureSession
的虚拟对象,但这不能解决问题.
I've tried use dummy object of AVCaptureSession
, but this didn't solve the problem.
编辑:第三方库因使用
AVCAptureSession
而导致崩溃.我已经联系他们,要求更改属性usesApplicationAudioSession
,如其他问题所述,并乞求"他们修复此问题.经过长时间的战斗,他们同意:).
Third party library had some additional crashed what exposed that they use
AVCAptureSession
. I've have contact them ask to change property usesApplicationAudioSession
as described in other question and "beg" them to fix it. After longer fight they agreed :).
推荐答案
I used category and method swizzling and it works like charm.
#import "AVCaptureSession+MethodSwizzling.h"
#import <objc/runtime.h>
static void MethodSwizzle(Class c, SEL origSEL, SEL overrideSEL) {
Method origMethod = class_getInstanceMethod(c, origSEL);
Method overrideMethod = class_getInstanceMethod(c, overrideSEL);
if(class_addMethod(c, origSEL, method_getImplementation(overrideMethod), method_getTypeEncoding(overrideMethod))) {
class_replaceMethod(c, overrideSEL, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
} else {
method_exchangeImplementations(origMethod, overrideMethod);
}
}
@implementation AVCaptureSession (MethodSwizzling)
- (id)initMethodSwizzling {
self = [self initMethodSwizzling]; // it is not recursion it is method swizzling
self.usesApplicationAudioSession = NO;
return self;
}
+ (void)load {
if (class_getInstanceMethod(self, @selector(setUsesApplicationAudioSession:))) {
// Swizzle methods only when it is possible to change usesApplicationAudioSession property.
MethodSwizzle(self, @selector(init), @selector(initMethodSwizzling));
}
}
@end
这篇关于使用视频/摄像机时未触发AVAudioSessionInterruptionNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!