How can I play a haptic feedback while AvCapture Session is running?

末鹿安然 提交于 2021-02-09 11:09:55

问题


When my Avcapture session is running and ready to record a video , I cannot play and audio files, vibrate or play any haptic feedback? I only found a solution for objective c but not swift.

Objective C Solution : Using vibrate and AVCaptureSession at the same time


回答1:


As long as you are using microphone in the AVCaptureSession, the haptic feedback will not play.

Apple tries to prevent the vibration from disrupting the microphone capture. This is noted in https://developer.apple.com/documentation/audiotoolbox/1405202-audioservicesplayalertsound

If you are not recording from the mic yet (as you said you are just in a "ready state"), then a solution is to delay adding the mic until you want to start recording.

Of course, while recording, you still may not play any haptic feedback.




回答2:


You can use setAllowHapticsAndSystemSoundsDuringRecording from iOS13 and later.

try session.setAllowHapticsAndSystemSoundsDuringRecording(true)


来源:https://stackoverflow.com/questions/44582128/how-can-i-play-a-haptic-feedback-while-avcapture-session-is-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!