• 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
Re: [NSSound isPlaying] fails to indicate sound termination in Lion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [NSSound isPlaying] fails to indicate sound termination in Lion


  • Subject: Re: [NSSound isPlaying] fails to indicate sound termination in Lion
  • From: Kyle Sluder <email@hidden>
  • Date: Sun, 22 Jul 2012 17:51:14 -0700

On Jul 22, 2012, at 5:43 PM, Jay Reynolds Freeman <email@hidden> 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
> ---------------------
> email@hidden
> 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 (email@hidden)
>
> 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:
>
> This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


References: 
 >[NSSound isPlaying] fails to indicate sound termination in Lion (From: Jay Reynolds Freeman <email@hidden>)
 >Re: [NSSound isPlaying] fails to indicate sound termination in Lion (From: Fritz Anderson <email@hidden>)
 >Re: [NSSound isPlaying] fails to indicate sound termination in Lion (From: Jay Reynolds Freeman <email@hidden>)

  • Prev by Date: Re: [NSSound isPlaying] fails to indicate sound termination in Lion
  • Next by Date: Re: [NSSound isPlaying] fails to indicate sound termination in Lion
  • Previous by thread: Re: [NSSound isPlaying] fails to indicate sound termination in Lion
  • Next by thread: Re: [NSSound isPlaying] fails to indicate sound termination in Lion
  • Index(es):
    • Date
    • Thread