将音频设备添加到AVCaptureSession时,UIImpactFeedbackGenerator不起作用 [英] UIImpactFeedbackGenerator Not Working When Audio Device Added to AVCaptureSession

查看:230
本文介绍了将音频设备添加到AVCaptureSession时,UIImpactFeedbackGenerator不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Adding microphone audio input to AVCaptureSession seems to disable UIImpactFeedbackGenerator.

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

一旦移除音频设备,反馈就会恢复.

Once the audio device is removed, feedback resumes.

这是正常行为吗?有办法解决吗?

Is this normal behavior? Is there a way around this?

我注意到股票iOS摄影机应用处于视频模式,长按缩略图似乎仍然可以使反馈正常工作.所以必须要有办法解决这个问题?

I notice stock iOS Camera app in video mode and long pressing on thumbnail seem to still make the feedback work. So there has to be a way around this?

推荐答案

这似乎是故意行为.

您可以停止捕获会话,播放触觉,然后恢复捕获会话,这似乎是相机应用程序正在执行的操作,因为当您窥视相机源时,会转到捕获到的最后一帧的静态静态图像.例如:

You can stop the capture session, play the haptic, then resume the capture session, which appears to be what the camera app is doing, as when you peek the camera feed goes to a blurred static image of the last frame captured. For example:

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

这篇关于将音频设备添加到AVCaptureSession时,UIImpactFeedbackGenerator不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆