aherlambang
aherlambang

Reputation: 14418

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?

Upvotes: 5

Views: 1137

Answers (1)

mjisrawi
mjisrawi

Reputation: 7936

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!

Upvotes: 5

Related Questions