3

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

  • sigh... I'm struggling with the same issue - I have AVCaptureSession with live preview and I also want to provide haptic feedbacks when user taps on buttons. If I add audioInput to my AVCaptureSession then I'm not able to produce haptic feedback at all. I tried to to add audioInput just before starting to record and to remove just after stopping but modifying configuration of the capture session leads to live preview hiccups (it becomes completely black for a fraction of a second). And I still have no idea how Snapchat and Instagram do this trick. – Dan Karbayev Jul 30 '17 at 01:54
  • Did you ever figure it out Daniyar? – gbhall Nov 14 '17 at 05:20
  • See my answer here https://stackoverflow.com/a/50009624/928911 – Max Sokolov Apr 24 '18 at 19:40

3 Answers3

3

You can use setAllowHapticsAndSystemSoundsDuringRecording from iOS13 and later.

try session.setAllowHapticsAndSystemSoundsDuringRecording(true)
Luca Angioloni
  • 2,243
  • 2
  • 19
  • 28
Shibo Qin
  • 31
  • 3
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.

samwize
  • 25,675
  • 15
  • 141
  • 186
0

session.setAllowHapticsAndSystemSoundsDuringRecording(true) is good for me!!
I'm using AudioQueueServices + CHHapticEngine

iRonCheng
  • 1
  • 4