当向AVCaptureSession添加音频设备时,UIImpactFeedbackGenerator无法工作

15

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

Translated sentence:

AVCaptureSession 增加麦克风音频输入后,似乎会导致 UIImpactFeedbackGenerator 失效。

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

一旦音频设备被移除,反馈会恢复。

这是正常的行为吗?有什么方法可以解决这个问题吗?

我发现在视频模式下长按缩略图使用iOS自带的相机应用程序似乎仍然使反馈功能正常。因此,肯定有一种方法可以解决这个问题吧?

3个回答

14

这似乎是一种故意的行为。

您可以停止捕获会话,播放触觉,然后恢复捕获会话,这似乎是相机应用正在执行的操作,因为当您窥视摄像头时,摄像头图像会变成上次捕获的模糊静态图像。例如:

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()
}

1
尝试打开AVAudioSessionsetAllowHapticsAndSystemSoundsDuringRecording

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接