How to play sounds in iPhone application

I start in this very confusing Objective-C game.

I would like to play a very short sound effect every time a certain button is pressed.

How can i do this?

Can I use an mp3 file? Or do I need to convert to wav?

+3
source share
2 answers

You can use System Sound Services to play short sounds:

CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef = CFBundleCopyResourceURL(mainBundle, CFSTR("filename"), CFSTR("aiff"), NULL);
SystemSoundID soundId;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundId);
AudioServicesPlaySystemSound(soundId);
CFRelease(soundFileURLRef)
Formats supported

.caf, .aiff and .wav.

+4
source

Not enough reputation to comment on @dstnbrkr's solution, so I will post it as an answer instead.

CFURLRef soundFileURLRef .

CFRelease(soundFileURLRef) (AudioServicesPlaySystemSound(soundId);), Core Foundation.

+1

Source: https://habr.com/ru/post/1733842/


All Articles