Reputation: 1795
To keep out any venting I may have I'm curious to know what people around here have been using (code snippet wise) to play short and small audio effects within their applications? Now that I'm working on a strictly iOS 5 ARC project my previous method is forbidden and throws errors.
So how does one go about simply playing a small 1 second audio file in their app with iOS 5 and Objective-C?
Thanks to anyone who positively contributes!
EDIT: Below is the code that sends errors with ARC and iOS 5
NSString *soundPath=[[NSBundle mainBundle] pathForResource:@"swoosh" ofType:@"caf"];
SystemSoundID sound;
AudioServicesCreateSystemSoundID((__bridge_retained CFURLRef)[NSURL fileURLWithPath:soundPath],&sound);
AudioServicesPlaySystemSound(sound);
Upvotes: 3
Views: 3503
Reputation: 17081
Try changing __bridge_retained
to just __bridge
and the ARC message should go away.
I believe AVAudioPlayer is higher level and has a bigger memory footprint so for playing short sounds it can be laggy and use more memory than necessary. See Multimedia Programming Guide: using Audio
Upvotes: 2
Reputation: 3184
This is code snippet I am using:
//alarm sound
self.alarmSoundPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:[[NSBundle mainBundle]
URLForResource:@"alarm"
withExtension:@"caf"]
error:0];
...
[alarmSoundPlayer play];
Upvotes: 1