A few sounds in the iPhone app?

I started playing one sound in the iPhone application that I started, but now I want to play several button-based sounds. To create a separate set of .m and .h files for each sound, and then include them all, does not seem to be the most efficient way to handle this from the point of view of coding ... then again, I am just starting with Cocoa and just finished mine first application.

Any help is appreciated. The key here is a few sounds, each of which is triggered by its own button or image. Thanks.

+3
source share
5 answers

MP3 AAC, . iPhone.

, , ( , ).

NSString *path = [[NSBundle mainBundle] pathForResource:@"dream" ofType:@"m4a"];  
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];  
theAudio.delegate = self;  
[theAudio play];

MP3 IMA4 ( ), ( , ):

/usr/bin/afconvert -f caff -d ima4 sound.mp3 sound.caf

- 2.2, AudioQueue, ( , ).

+8

iPhone, , , .

, ,

-(void)Play:(NSString*)sSoundFile {
    // play sound file here
}
+4

iPhone, ? . , , , ...

+2

@rustyshelf - ? #import, , audioPlayerDidFinishPlaying, audioPlayerDecodeErrorDidOccur. .

+1

http://www.icodeblog.com/2009/05/04/iphone-game-programming-tutorial-part-4-basic-game-audio/

in this example in ios5 you need to put CFURLRef soundurl = (__ bridge CFURLRef) [NSURL fileURLWithPath: objstring];

instead

CFURLRef soundurl = (CFURLRef) [NSURL fileURLWithPath: objstring];

Hardik Mamtor

0
source

All Articles