Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 903
Kyle Avatar asked Mar 11 '15 11:03

Kyle


1 Answers

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);
AudioServicesPlaySystemSound(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.

like image 105
Rob Sanders Avatar answered Sep 30 '22 00:09

Rob Sanders