开发者

Vibrate iPhone while Recording

开发者 https://www.devze.com 2022-12-11 12:10 出处:网络
I\'m trying to get my iPhone to vibrate while I\'m recording. I\'ve tried this: UInt32 category = kAudioSessionCategory_PlayAndRecord;

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?


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


My guess is that the vibration functions are specifically suppressed during audio recording. You could easily test this by doing something else that would normally make the phone vibrate (e.g. send yourself a text message with the mute switch on) while you are recording your audio—my bet is that it won't vibrate for that, either.

This earlier thread confirms my view.

0

精彩评论

暂无评论...
验证码 换一张
取 消