Re: simple(?) NSSound selector not recognized error
Re: simple(?) NSSound selector not recognized error
- Subject: Re: simple(?) NSSound selector not recognized error
- From: Shawn Erickson <email@hidden>
- Date: Tue, 14 Aug 2007 21:12:22 -0700
On Aug 14, 2007, at 8:55 PM, Russ McBride wrote:
In my header file I've got:
NSSound *theSound;
And in my implementation file I've got a couple of methods, each called from a button click:
- (IBAction)lightning:(id)sender { NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"lightning" ofType:@"au"]; NSSound *theSound = [[NSSound alloc] initWithContentsOfFile:soundFile byReference:YES]; [theSound play]; // [theSound pause] This works just fine if called here.
}
- (IBAction) pauseSound:(id)sender { [theSound pause]; [infoTextField setStringValue:@"Playback paused"]; }
I've got a "pause" button that's connected to the "pauseSound" method. The sound plays fine, but I can't pause, resume, or stop the sound in another method. I get the following error:
SoundFun[15316] *** -[NSPathStore2 pause]: selector not recognized [self = 0x3466e0]
I checked the retainCount and theSound isn't being deallocated prematurely.
Checking retainCount often leads to more confusion then to helping understand an issue.
In lightning: you are assigning a newly allocated NSSound instance to a local variable called "theSound". This location variable is hiding the instance variable called theSound. You should see a warning about this when you compile (unless you that warning disabled).
Additionally you do nothing to properly memory manage the sound instance (at least nothing is apparent in the code you posted). The cleanest and Cocoa consistent way is to implement a proper accessor pair for the instance variable "theSound". The accessor can take care of the memory management for you.
Also I would encourage some other name then "theSound".
-Shawn |
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden