-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaysound.m
More file actions
33 lines (26 loc) · 814 Bytes
/
playsound.m
File metadata and controls
33 lines (26 loc) · 814 Bytes
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
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
if(argc > 1){
NSString *filename = [NSString stringWithCString:argv[1]];
NSLog(@"Trying to play %@", filename);
NSURL *url = [[NSURL alloc] initWithString:filename];
NSSound *snd = [NSSound alloc];
if(url)
snd = [snd initWithContentsOfURL:url byReference:false];
else
snd = [snd initWithContentsOfFile:filename byReference:false];
if(snd){
NSLog(@"duration = %f", [snd duration]);
[snd play];
while([snd isPlaying]) sleep(1); //fulhack? jappjapp
[snd release];
}else
NSLog(@"Failed to load sound %@", filename);
} else {
NSLog(@"You must specify file or URL");
}
[pool drain];
return 0;
}