开发者

iPhone vibration while playing audio

开发者 https://www.devze.com 2023-04-06 14:06 出处:网络
My application plays audio using AudioQueue and AudioSession. I can\'t stop playing according to application workflow. Currently, my customer ask me to perform iPhone vibration according to some condi

My application plays audio using AudioQueue and AudioSession. I can't stop playing according to application workflow. Currently, my customer ask me to perform iPhone vibration according to some conditions. I've tried to perform it with AudioServices playing vibration as system sound or alert sound. There is not positive result. Could somebody help me and tell how to implement it? I'm making legal application for non jailbreaked iPhones and can't use custom freamworks because Apple can reject ap开发者_JAVA百科plication.

Thank you.


Solved using this solution :)

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;         
[audioSession setCategory :AVAudioSessionCategoryPlayback  error:&err];         
AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord  error:&err];


This is how I get the vibration:

#import <AudioToolbox/AudioToolbox.h>

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;         
[audioSession setCategory :AVAudioSessionCategoryPlayback  error:&err];         
AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);

Hope it helps


For reference, I'm not using AudioQueue but an AVAudioEngine to record something, and for my case I pinpointed it down to having to pause the input in order to play the vibration properly with AudioServicesPlaySystemSound during a record session.

So in my case, I did something like this

audioEngine?.pause()
AudioServicesPlaySystemSound(1519)
do {
  try audioEngine.start()
} catch let error {
  print("An error occurred starting audio engine. \(error.localizedDescription)")
}
0

精彩评论

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