forked from atomton/ATMHud
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathATMSoundFX.m
57 lines (48 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
55
56
57
/*
* ATMSoundFX.m
* ATMHud
*
* Created by Marcel Müller on 2011-03-01.
* Copyright (c) 2010-2011, Marcel Müller (atomcraft)
* Copyright (c) 2012-2014, David Hoerl
* All rights reserved.
*
* https://github.com/atomton/ATMHud (original)
*/
#import <AudioToolbox/AudioServices.h>
#import "ATMSoundFX.h"
@implementation ATMSoundFX
{
SystemSoundID soundID;
}
- (instancetype)initWithContentsOfFile:(NSString *)path
{
if ((self = [super init])) {
NSURL *aFileURL = [NSURL fileURLWithPath:path isDirectory:NO];
if (aFileURL) {
SystemSoundID aSoundID;
OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)aFileURL, &aSoundID);
if (error == kAudioServicesNoError) {
soundID = aSoundID;
} else {
self = nil;
}
} else {
self = nil;
}
}
return self;
}
- (void)dealloc
{
if (soundID) {
// one presumes dealloc called even if init failed, since super succeeded...
AudioServicesDisposeSystemSoundID(soundID);
NSLog(@"SOUND DEALLOC");
}
}
- (void)play
{
AudioServicesPlaySystemSound(soundID);
}
@end