Categories
- Code (3)
- Code Snippets (12)
- git (1)
- Hardware (1)
- News (5)
- Objective-C (6)
- Precompiled (4)
- Programming (1)
- Review (1)
- Swift (9)
- Swift Standard Library (3)
- Tips (3)
- Tutorial (22)
- Uncategorized (3)
- WWDC (1)
-
Recent Posts
Meta
-
Tag Archives: AudioToolbox
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// 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); |
Snippet: Playing a System Sound
If you are using ARC see: “Playing a System Sound (ARC Version)”. Today I needed to add a simple beep sound to an app. The code snippet below shows all the relevant calls.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// 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((CFURLRef)url, &mBeep); // Play the sound AudioServicesPlaySystemSound(mBeep); // Dispose of the sound AudioServicesDisposeSystemSoundID(mBeep); |
If I had found a page … Continue reading