Re: Question & one Answer for NSButton & activation/click sound when in Toggle mode. Better answer?
Re: Question & one Answer for NSButton & activation/click sound when in Toggle mode. Better answer?
- Subject: Re: Question & one Answer for NSButton & activation/click sound when in Toggle mode. Better answer?
- From: tyler <email@hidden>
- Date: Mon, 6 Aug 2001 22:42:18 -0700
Hmm. So the one aspect of this "let the target handle it" fix, is that
there is a significant pause the first time you click on the button
(actually loading the sound? or perhaps initializing the NSSound object
somehow?). It's quite fast after that one first time, but the pause
(heck, it's almost a HANG it's so long) is a bummer.
Any ideas to get NSSound to preload or pre-initialize or whatever so it
doesn't hang like that?
Thanks!
peace,
tyler
On Monday, August 6, 2001, at 10:36 PM, tyler wrote:
OK. Here's an answer - just make my target of the button handle the
sound... seems easier, but a bit less elegant than having the button do
it.
anybody got a better fix?
tyler
//
-----------------------------------------------------------------------------------
Ok. So here's the implementation that has the NSButton target handle
the sound
in case anyone might find it useful. Shockingly simple (let's hear it
for Cocoa!).
// In my target object (controller for window) I have a method that is
the action method of the NSButton:
- (IBAction)doSwitch:(id)sender
{
[self playSwitchSound]; // play sound each time it's hit.
// ... do other stuff here in response to button being clicked upon.
}
// A simple initialization in awakeFromNib to pre-load the sound:
- (void) awakeFromNib
{
NSString * path = [[NSBundle mainBundle] pathForSoundResource:
@"click.aiff"];
clickSnd = [[NSSound alloc] initWithContentsOfFile: path
byReference: YES]; // byRef ??
// anyone know what the "byReference" param is for/does?
}
// and the method to actually play the sound
- (void) playSwitchSound
{
BOOL b;
if ( clickSnd )
b = [clickSnd play];
// Anyone know what the boolean return means?
}