• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Two NSSound problems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Two NSSound problems


  • Subject: Two NSSound problems
  • From: Jeff Biggus <email@hidden>
  • Date: Thu, 4 Mar 2004 14:18:06 -0600

I wrote a small command-line tool to play audio files. It basically just creates an NSSound object and plays it until it's done. Works great for most all audio files, and the sound tracks of quicktime movies. However, I've run into two problems, perhaps related. 1) It doesn't always load a file, and the program hangs; 2) It doesn't always properly stop playing. It does both things most (80%?) of the time.

As for loading, it doesn't always successfully initWithContentsOfFile:. It will, on the occasional mp3 file, just stall and the program will hang. In other words, for about 20% of the mp3 files that I try, this line will hang:

sound = [[NSSound alloc] initWithContentsOfFile:soundFileString byReference:YES];

(The boolean set either way will produce the same results.) I had hoped that a failure to load would at least return nil or some such, but it (the program, in this case single-threaded) just stops.

On the debugging side, it's always the same MP3 files that hang, and it seems to be on a album-by-album basis. But, when I check the "Encoded with" tag, there's no consistent info. (example: some encoded with iTunes X v1.1.1 don't play, but others do.) Also, bit rate, sample rate, size, channels, and format all don't seem to matter. I can't find any mention anywhere about this. Apple's docs mention that it should "fail" if it doesn't load, and it certainly does fail, but doesn't return from the method call so that I can do anything about it.

As for stopping, the object I use to play the sound is also assigned to be the sound's delegate. I then have the following methods (it's almost the whole program). For some reason, some songs never escape the while loop. Normally, the sound:didFinishPlaying: method gets called fine, but not always.

-(id)initWithSoundFile:(NSString *)soundFileString {
if (self = [super init]) {
sound = [[NSSound alloc] initWithContentsOfFile:soundFileString byReference:YES];
[sound setDelegate:self];
}
return self;
}

-(void)playUntilDone {
[sound play];
while ([sound isPlaying]) {
NSDate *limit = [NSDate dateWithTimeIntervalSinceNow: 0.5];
[[NSRunLoop currentRunLoop] runUntilDate: limit];
}
}

-(void)sound:(NSSound *)aSound didFinishPlaying:(BOOL)finished {
if (finished && [aSound isPlaying]) [aSound stop];
}

(Here's the download if anyone else wants to try it out: http://osx.hyperjeff.net/_files/play.gz )
I'm stumped. Any thoughts? Are there currently bugs in NSSound that I should know about?
-Jeff
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Prev by Date: PDF viewing (like Preview)
  • Next by Date: SFAuthorizationView - again...
  • Previous by thread: Re: PDF viewing (like Preview)
  • Next by thread: SFAuthorizationView - again...
  • Index(es):
    • Date
    • Thread