-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTomatoSound.m
45 lines (37 loc) · 1.22 KB
/
TomatoSound.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
#import "TomatoSound.h"
@interface TomatoSound(Private)
- (SystemSoundID)initializeSoundFromFile:(NSString *)file;
@end
@implementation TomatoSound
- (id)init {
if (self = [super init]) {
tomatoSound = [self initializeSoundFromFile:@"Bell"];
breakSound = [self initializeSoundFromFile:@"Hamon"];
}
return self;
}
- (BOOL)isEnabled {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"TOMSound"];
}
- (SystemSoundID)initializeSoundFromFile:(NSString *)file {
NSBundle *mainBundle = [NSBundle mainBundle];
NSURL *aFileURL = [NSURL fileURLWithPath:[mainBundle pathForResource:file ofType:@"aif"] isDirectory:NO];
if (aFileURL != nil) {
SystemSoundID aSoundID;
OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)aFileURL, &aSoundID);
if (error == kAudioServicesNoError) {
return aSoundID;
} else {
NSLog(@"Error %d loading sound %@", error, file);
return 0;
}
}
return 0;
}
- (void)tomatoEnded:(NSNotification *)notification {
AudioServicesPlaySystemSound(tomatoSound);
}
- (void)breakEnded:(NSNotification *)notification {
AudioServicesPlaySystemSound(breakSound);
}
@end