On Jul 22, 2012, at 5:43 PM, Jay Reynolds Freeman <jay_reynolds_free...@mac.com> wrote:
> The "sleep" was only for instrumentation; without the sleep and the NSLog, > the code exhibits the problem described. And [NSSound play] is supposed to > run asynchronously ... > > -- Jay Reynolds Freeman > --------------------- > jay_reynolds_free...@mac.com > http://JayReynoldsFreeman.com (personal web site) > > > > On Jul 22, 2012, at 5:27 PM, Fritz Anderson wrote: > > On 22 Jul 2012, at 6:12 PM, Jay Reynolds Freeman wrote: > >> [wraithIconView setImage:wraithIconImageOM]; // "OM" means "Open Mouth". >> [self showIconViewAbruptly:YES]; >> [toPlay play]; >> while( [toPlay isPlaying] ) { >> NSLog(@"Still playing..."); // Instrumentation for debugging. >> usleep( 100000 ); // Instrumentation for debugging. >> ; >> } >> [wraithIconView setImage:wraithIconImage]; >> [self showIconViewAbruptly:YES]; >> >> In this code, "toPlay" is an instance of NSSound initialized to an aif file >> that takes about half a second to play, and "showIconView abruptly" just >> sets the alpha of the image to 1 or 0 according to whether the argument is >> YES or NO. >> >> All this works like gangbusters under 10.6.8 -- the "NSLog" prints about six >> times, which is consistent with the length of the sound and the 0.1-second >> sleep. But under 10.7.4, The "NSLog" prints forever, or so it seems, even >> though the sound has played to all intents and purposes normally; that is, >> the kitty has said "meow" and then stopped making any sound. >> Notwithstanding, my app is hung in an infinite loop. >> >> So nominally, it looks as if possibly [NSSound isPlaying] is not correctly >> indicating sound termination under Lion, or perhaps the sound is actually >> not terminating under Lion, or who knows, maybe it is something else. >> >> [NSSound play] is supposed to be asynchronous, so there should be no problem >> trying to do other things while the sound is playing. > > Except I don't think you _are_ doing other things while the sound is playing, > at least not in the sense that Cocoa means it. Bringing the main thread to a > dead halt and not returning to the run loop is asking for trouble. NSSound is > within its rights to depend on the main run loop to manage its status events, > and apparently that's what it does in Lion. > > The class provides a delegate method (-sound:didFinishPlaying:) to let you > know when it's done, to a precision of less than 0.1 seconds, without halting > the program. Put your wraith cleanup there. > > Calling any kind of sleep on the main thread means you're doing it wrong. On > other threads, it means that you're _probably_ doing it wrong. > > — F > > -- > Fritz Anderson > Xcode 4 Unleashed: Okay, let me be blunt — why buy just one? > <http://x4u.manoverboard.org/> > > > > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/kyle%40ksluder.com > > This email sent to k...@ksluder.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com