NSString* pathOfSound = [[NSBundle mainBundle] pathForResource:@"mySound" ofType:@"caf"];
NSData* dataOfSound = [[NSData alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathOfSound]];
Then, whenever you want to play sound, create a new object of AVAudioPlayer.
AVAudioPlayer* player = [[AVAudioPlayer alloc] initWithData:dataOfSound error:NULL];
player.delegate = self; // for releasing object, see "Playing sound with AVAudioPlayer"
[player play];
No comments:
Post a Comment