Snippet: Playing a System Sound (ARC Version)

A minor change is needed to the “Playing a System Sound” code snippet.
A __bridge modifier has to be added to the CFURLRef cast.

// Required import... Also need AudioToolbox.framework
#import <AudioToolbox/AudioToolbox.h>

// ivar 
SystemSoundID mBeep;

// Create the sound ID
NSString* path = [[NSBundle mainBundle] 
                     pathForResource:@"Beep" ofType:@"aiff"];
NSURL* url = [NSURL fileURLWithPath:path];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &mBeep);

// Play the sound
AudioServicesPlaySystemSound(mBeep);

// Dispose of the sound
AudioServicesDisposeSystemSoundID(mBeep);

About idz

A professional software engineer dabbling in iOS app development.
This entry was posted in Code Snippets and tagged , , , . Bookmark the permalink.

One Response to Snippet: Playing a System Sound (ARC Version)

  1. Pingback: Snippet: Playing a System Sound | iOS Developer Zone

Leave a Reply