【问题标题】:AVAudioSessionInterruptionNotification not fired when Video/Camera is used使用视频/相机时未触发 AVAudioSessionInterruptionNotification
【发布时间】:2014-06-13 12:28:59
【问题描述】:

我有一些 SIP 应用程序。在我使用音频之前,只有一切正常工作,我在必要时收到了AVAudioSessionInterruptionNotification

使用视频时出现问题(接收和发送相机源)。一旦我对视频使用会话,即使仅使用稍后的音频,也不会再次触发通知。

我该如何解决这个问题?我找到了类似的topic,但答案是提示,我不完全明白。此外,我没有“相机/捕获设备”和“AVCaptureSession”,因为音频和视频流是由封闭的第三方库提供的,但我的代码必须处理中断。

我是否必须更改某些属性才能始终触发此通知(链接主题建议),或者我应该使用替代通知。
我正在挖掘文档,但没有找到任何对我有用的东西。

我试过使用AVCaptureSession的虚拟对象,但这并没有解决问题。


编辑:第三方库有一些额外的崩溃,暴露了他们使用AVCAptureSession。我已经联系他们要求更改属性usesApplicationAudioSession,如other question 中所述,并“请求”他们修复它。经过长时间的战斗,他们同意了:)。

【问题讨论】:

    标签: ios iphone objective-c video avaudiosession


    【解决方案1】:

    我使用了类别和method swizzling,它就像魅力一样。

    #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
    

    【讨论】:

      猜你喜欢
      • 2013-12-18
      • 1970-01-01
      • 2014-11-13
      • 1970-01-01
      • 2013-08-20
      • 1970-01-01
      • 2021-10-20
      • 2015-11-27
      • 2023-04-09
      相关资源
      最近更新 更多