NSSound on iphone

I was looking for some time how to play sound on iphone, and I think it is something like:

[[NSSound soundNamed:@"cat.mp3"] play]; 

But NSSound is in AppKit ... any suggestions? I know that there is a very simple answer to this question, but today my searches do not give any result ...

+4
source share
2 answers

the new AVFoundation class is the easiest way to play audio on iPhone, although it is only for firmware 2.2:

 AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; [audioPlayer play]; 

you just need this import in the class that uses it:

 #import <AVFoundation/AVAudioPlayer.h> 
+10
source

Sound signals from the Audio Toolbox are great for short asynchronous playback.

 // Initialize CFBundleRef mainBundle; mainBundle = CFBundleGetMainBundle (); // Init each sound CFURLRef tapURL; SystemSoundID tapSound; tapURL = CFBundleCopyResourceURL(mainBundle, CFSTR("tap"), CFSTR("aif"), NULL); AudioServicesCreateSystemSoundID(tapURL, &tapSound); // Play the sound async AudioServicesPlaySystemSound(tapSound); 

I do not have MP3 files to work with AudioServicesPlaySystemSound . But it plays AIF files perfectly.

+7
source

All Articles