How to play a sound effect

- by

This is a rather cryptic setup, but here’s how it works:

SystemSoundID soundID;
NSString *soundFile = [[NSBundle mainBundle]pathForResource:@"yourfile" ofType:@"wav"];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:soundFile], &soundID);

This snippet assumes you’re using a file called yourfile.wav which needs to present in your project. You’ll also need to import the AudioToolbox Framework and import it in your header file.

If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.