Kyle Kyle - 8 months ago 42
Objective-C Question

Best method to play an short audio sound on iOS 8.2

What is the best way to play an audio on iOS 8.2?


The easiest way is to import the AudioToolbox framework like so #import <AudioToolbox/AudioToolbox.h> then all you need to do is this:

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

This is best for really short sounds like beeps e.t.c because you wont have much control over the sounds like you would with AVAudioPlayer.