diff -ruN sndplay/main.m sndplay-patched2/main.m --- sndplay/main.m Thu May 17 11:11:00 2001 +++ sndplay/main.m Tue Nov 25 19:36:30 2003 @@ -1,10 +1,46 @@ #import #import +@interface NSSoundPlayer:NSObject { + BOOL isDone; + NSRunLoop * myrl; +} + +- (void)play:(NSString*)thePath; +- (void)sound: (NSSound *)sound didFinishPlaying:(BOOL)aBool; +@end + +@implementation NSSoundPlayer + +- (void)play: (NSString *)thePath { + + NSData *data = [NSData dataWithContentsOfFile:thePath]; + + NSSound *sound; + myrl = [NSRunLoop currentRunLoop]; + sound = [[NSSound alloc] initWithData:data]; + + [sound setDelegate: self]; + + [sound play]; + [myrl run]; + +} + + +- (void)sound: (NSSound *)sound didFinishPlaying:(BOOL)aBool { + exit(0); +} + +@end + + int main (int argc, const char * argv[]) { - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - NSSound *sound; + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSString *thePath; + NSSoundPlayer *myPlayer; if( argc != 2 ) { fprintf(stderr,"Usage: sndplay sound.[snd][aiff][wav]\n "); @@ -18,14 +54,11 @@ fprintf(stderr,"Usage: sndplay sound.[snd][aiff][wav]\n "); return -1; } - NS_DURING - NSString *thePath = [NSString stringWithCString:argv[1]]; - NSData *data = [NSData dataWithContentsOfFile:thePath]; - sound = [[NSSound alloc] initWithData:data]; - [sound play]; - while ( [sound isPlaying] ); - NS_HANDLER - NS_ENDHANDLER + + myPlayer = [NSSoundPlayer alloc]; + thePath = [NSString stringWithCString:argv[1]]; + [myPlayer play: thePath]; [pool release]; return 0; -} + +} \ No newline at end of file