Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 54 lines (43 sloc) 1.295 kb
bc837bb Adding audio files
coreyfloyd authored
1 //
2 // SoundEffect.m
3 // Phoney Crack
4 //
5 // Created by Marcus Kratz on 3/24/09.
6 // Copyright 2009 Marcus Kratz Electrical. All rights reserved.
7 //
8
9 #import "SoundEffect.h"
10
11
12 @implementation SoundEffect
13 + (id)soundEffectWithContentsOfFile:(NSString *)aPath {
14 if (aPath) {
15 return [[[SoundEffect alloc] initWithContentsOfFile:aPath] autorelease];
16 }
17 return nil;
18 }
19
20 - (id)initWithContentsOfFile:(NSString *)path {
21 self = [super init];
22
23 if (self != nil) {
24 NSURL *aFileURL = [NSURL fileURLWithPath:path isDirectory:NO];
25
26 if (aFileURL != nil) {
27 SystemSoundID aSoundID;
28 OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)aFileURL, &aSoundID);
29
30 if (error == kAudioServicesNoError) { // success
31 _soundID = aSoundID;
32 } else {
33 NSLog(@"Error %d loading sound at path: %@", error, path);
34 [self release], self = nil;
35 }
36 } else {
37 NSLog(@"NSURL is nil for path: %@", path);
38 [self release], self = nil;
39 }
40 }
41 return self;
42 }
43
44 -(void)dealloc {
45 AudioServicesDisposeSystemSoundID(_soundID);
46 [super dealloc];
47 }
48
49 -(void)play {
50 AudioServicesPlaySystemSound(_soundID);
51 }
52
53 @end
Something went wrong with that request. Please try again.