Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vibrate iPhone while Recording

I'm trying to get my iPhone to vibrate while I'm recording.

I've tried this:

UInt32 category = kAudioSessionCategory_PlayAndRecord; 
status |= AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);
UInt32 allowMixing = true;
status |= AudioSessionSetProperty (
      kAudioSessionProperty_OverrideCategoryMixWithOthers,  // 1
      sizeof (allowMixing),                                 // 2
      &allowMixing                                          // 3
       );
status |= AudioSessionSetProperty(
      kAudioSessionProperty_OtherMixableAudioShouldDuck, // 1
      sizeof (allowMixing),        // 2
      &allowMixing          // 3
       );

As suggested here. Then vibrate the device later on by calling

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

But it does not work. But it does not vibrate. It records fine, and if I call a vibrate moments before I stop recording it vibrates after stop it.

Apparently it's a bug, does anyone know of a work around?

like image 669
jamesrom Avatar asked Nov 17 '09 15:11

jamesrom


1 Answers

AT LAST! As of iOS 13, there is a new property on AVAudioSession

        let _ = try? AVAudioSession.sharedInstance().setCategory(.playAndRecord)
        if #available(iOS 13.0, *) {
            let _ = try? AVAudioSession.sharedInstance().setAllowHapticsAndSystemSoundsDuringRecording(true)
        }
like image 177
Logan Sease Avatar answered Oct 13 '22 22:10

Logan Sease