-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsound.m
43 lines (34 loc) · 1011 Bytes
/
sound.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
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <AVFoundation/AVFoundation.h>
#import <pthread.h>
#import "sound.h"
#define PLAY_DURATION_SECONDS 10
void* playThreadFn(void *arg) {
char *filePath = (char*)arg;
@autoreleasepool {
NSString *urlString = [[NSString alloc] initWithUTF8String:filePath];
NSURL *url = [NSURL fileURLWithPath:urlString];
NSError *error;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if (error) {
NSLog(@"Error in audioPlayer: %@",
[error localizedDescription]);
} else {
[player play];
}
sleep(PLAY_DURATION_SECONDS);
}
return NULL;
}
void playSound(char *filePath) {
pthread_t threadId;
pthread_create(&threadId, NULL, playThreadFn, filePath);
}
//int main(int argc, const char * argv[]) {
// @autoreleasepool {
// char *path = "/Users/ddcmhenry/dev/funtastic/branches/thunder/sound/drone_ok.mp3";
// play(path);
// return 0;
// }
//}