-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.m
79 lines (67 loc) · 2.04 KB
/
test.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <AVFoundation/AVFoundation.h>
@interface Listener : NSObject <AVAudioPlayerDelegate>
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player
successfully:(BOOL)flag;
- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player
error:(NSError *)error;
- (void)play:(char *)path;
@property (nonatomic, strong) AVAudioPlayer* player;
@end
@implementation Listener
@synthesize player = mPlayer;
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)data successfully:(BOOL)flag {
printf("DONE\n");
// NSLog(@"done!");
}
- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error
{
NSLog(@"%s error=%@", __PRETTY_FUNCTION__, error);
}
- (void)play:(char *)path {
NSString *urlString = [[NSString alloc] initWithUTF8String:path];
NSURL *url = [NSURL fileURLWithPath:urlString];
NSError *error;
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
self.player.delegate = self;
if (error) {
NSLog(@"Error in audioPlayer: %@",
[error localizedDescription]);
} else {
[self.player play];
}
}
@end
//void play(char* path) {
// @autoreleasepool {
//
// NSString *urlString = [[NSString alloc] initWithUTF8String:path];
// NSURL *url = [NSURL fileURLWithPath:urlString];
// NSError *error;
// AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
//
// player.delegate = [[Listener alloc] init];
//
// if (error) {
// NSLog(@"Error in audioPlayer: %@",
// [error localizedDescription]);
// } else {
// [player play];
// }
//
//
//
// sleep(10);
// }
//}
int main(int argc, const char * argv[]) {
@autoreleasepool {
Listener *l = [[Listener alloc] init];
char *path = "/Users/ddcmhenry/dev/funtastic/branches/thunder/sound/drone_ok.mp3";
[l play:path];
sleep(100000);
// play("/Users/ddcmhenry/dev/funtastic/branches/thunder/sound/drone_ok.mp3");
return 0;
}
}