【问题标题】:UIImpactFeedbackGenerator Not Working When Audio Device Added to AVCaptureSession音频设备添加到 AVCaptureSession 时 UIImpactFeedbackGenerator 不工作
【发布时间】:2018-03-26 19:07:29
【问题描述】:

AVCaptureSession 添加麦克风音频输入似乎会禁用UIImpactFeedbackGenerator

let audioDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeAudio)
let audioDeviceInput = try AVCaptureDeviceInput(device: audioDevice)
if self.session.canAddInput(audioDeviceInput) {
   self.session.addInput(audioDeviceInput)
}

移除音频设备后,反馈会恢复。

这是正常行为吗?有没有办法解决这个问题?

我注意到在视频模式下的股票 iOS 相机应用程序和长按缩略图似乎仍然可以使反馈起作用。那么,一定有办法解决这个问题吗?

【问题讨论】:

    标签: ios xcode avfoundation audio-recording haptic-feedback


    【解决方案1】:

    这似乎是一种故意行为。

    您可以停止捕捉会话,播放触觉,然后恢复捕捉会话,这似乎是相机应用正在执行的操作,因为当您偷看相机时,相机馈送会转到捕捉到的最后一帧的模糊静态图像。例如:

    self.session.stopRunning()
    // Play haptic
    UINotificationFeedbackGenerator().notificationOccurred(.warning)
    // Not completely sure if this delay is needed but you might need to wait until the run loop after the haptic plays to resume capture session
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.1)
    {
    
        self.session.startRunning()
    }
    

    【讨论】:

      【解决方案2】:

      音频会话(通过 AVAudioPlayer、AVCaptureMovieFileOutput 等),则手机不会振动。

      我不确定,但 99% 不能使用 AVCaptureMovieFileOutput。 请提供更多信息: https://developer.apple.com/documentation/audiotoolbox/1405202-audioservicesplayalertsound

      【讨论】:

        【解决方案3】:

        尝试开启setAllowHapticsAndSystemSoundsDuringRecordingAVAudioSession

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-12-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多