Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vibrate iphone/ipod with custom sound

I have my own sound that I want to play while the phone vibrates, the most common thing to do is to do:

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

but this is using the system's sound. Is there a way to use my own sound? What is the format of the sound that I can use?

like image 445
aherlambang Avatar asked Aug 07 '11 03:08

aherlambang


People also ask

Can you make custom vibrations on iPhone?

Ringtones play for incoming calls, clock alarms, and the clock timer; text tones are used for text messages, new voicemail, and other alerts. Tap Vibration, then choose a vibration pattern, or tap Create New Vibration to create your own.

How do you make a custom text vibrate on iPhone?

Launch the Settings app on your iPhone. Tap Sounds & Haptics. Tap on the alert category you'd like to set a custom vibration for. In this example, I'll use Text Tone.

How do I make the sound on my iPhone vibrate?

Choose when your device vibrates On iPhone 7 and later, go to Settings > Sounds & Haptics. On earlier iPhone models, go to Settings > Sounds. You can choose if you want your iPhone to vibrate when set to Ring or Silent mode. If you turn off both settings, your iPhone won't vibrate.


1 Answers

Check out AudioServicesPlayAlertSound, this will play a custom sound and vibrate if the user has vibration enabled in their sound settings. The proper usage would be something like this...

SystemSoundID soundFileObject;

NSURL * soundFileURL= [[NSBundle mainBundle] URLForResource: @"mySoundFile" withExtension: @"aif"];

CFURLRef soundFileURLRef = (CFURLRef) [soundFileURL retain];

AudioServicesCreateSystemSoundID (soundFileURLRef, &soundFileObject);

AudioServicesPlayAlertSound (soundFileObject);

The supported file types are .caf, .aif, or .wav according to the above link. Hope that helps!

like image 172
mjisrawi Avatar answered Oct 22 '22 03:10

mjisrawi