-
Notifications
You must be signed in to change notification settings - Fork 1
/
ATMSoundFX.m
executable file
·54 lines (44 loc) · 1.18 KB
/
ATMSoundFX.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* ATMSoundFX.m
* ATMHud
*
* Created by Marcel Müller on 2011-03-01.
* Copyright (c) 2010-2011, Marcel Müller (atomcraft)
* All rights reserved.
*
* https://github.com/atomton/ATMHud
*/
#import "ATMSoundFX.h"
@implementation ATMSoundFX
+ (id)soundEffectWithContentsOfFile:(NSString *)aPath {
if (aPath) {
return [[[ATMSoundFX alloc] initWithContentsOfFile:aPath] autorelease];
}
return nil;
}
- (id)initWithContentsOfFile:(NSString *)path {
self = [super init];
if (self != nil) {
NSURL *aFileURL = [NSURL fileURLWithPath:path isDirectory:NO];
if (aFileURL != nil) {
SystemSoundID aSoundID;
OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)aFileURL, &aSoundID);
if (error == kAudioServicesNoError) {
_soundID = aSoundID;
} else {
[self release], self = nil;
}
} else {
[self release], self = nil;
}
}
return self;
}
-(void)dealloc {
AudioServicesDisposeSystemSoundID(_soundID);
[super dealloc];
}
-(void)play {
AudioServicesPlaySystemSound(_soundID);
}
@end