当音频设备添加到 AVCaptureSession 时,UIImpactFeedbackGenerator 不工作
UIImpactFeedbackGenerator Not Working When Audio Device Added to AVCaptureSession
向 AVCaptureSession
添加麦克风音频输入似乎会禁用 UIImpactFeedbackGenerator
。
let audioDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeAudio)
let audioDeviceInput = try AVCaptureDeviceInput(device: audioDevice)
if self.session.canAddInput(audioDeviceInput) {
self.session.addInput(audioDeviceInput)
}
移除音频设备后,反馈将恢复。
这是正常现象吗?有解决办法吗?
我注意到股票 iOS 相机应用程序在视频模式下和长按缩略图似乎仍然可以使反馈有效。那么,必须有办法解决这个问题吗?
这似乎是一种故意的行为。
您可以停止捕捉会话,播放触觉,然后恢复捕捉会话,这似乎是相机应用程序正在做的事情,因为当您偷看相机馈送时,会看到最后一帧的模糊静态图像捕获。例如:
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()
}
音频会话(通过 AVAudioPlayer、AVCaptureMovieFileOutput 等),然后 phone 将不会振动。
我不确定,但 99% 的人没有使用 AVCaptureMovieFileOutput。
请提供更多信息:
https://developer.apple.com/documentation/audiotoolbox/1405202-audioservicesplayalertsound
尝试打开 AVAudioSession
的 setAllowHapticsAndSystemSoundsDuringRecording
。
向 AVCaptureSession
添加麦克风音频输入似乎会禁用 UIImpactFeedbackGenerator
。
let audioDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeAudio)
let audioDeviceInput = try AVCaptureDeviceInput(device: audioDevice)
if self.session.canAddInput(audioDeviceInput) {
self.session.addInput(audioDeviceInput)
}
移除音频设备后,反馈将恢复。
这是正常现象吗?有解决办法吗?
我注意到股票 iOS 相机应用程序在视频模式下和长按缩略图似乎仍然可以使反馈有效。那么,必须有办法解决这个问题吗?
这似乎是一种故意的行为。
您可以停止捕捉会话,播放触觉,然后恢复捕捉会话,这似乎是相机应用程序正在做的事情,因为当您偷看相机馈送时,会看到最后一帧的模糊静态图像捕获。例如:
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()
}
音频会话(通过 AVAudioPlayer、AVCaptureMovieFileOutput 等),然后 phone 将不会振动。
我不确定,但 99% 的人没有使用 AVCaptureMovieFileOutput。 请提供更多信息: https://developer.apple.com/documentation/audiotoolbox/1405202-audioservicesplayalertsound
尝试打开 AVAudioSession
的 setAllowHapticsAndSystemSoundsDuringRecording
。