release sounds and memory manegment
hello in my application i use the code below to handle and play sounds, I want to know if i need to release any things or nothing to do.
the code :
-(void) playNote: (NSString*) note type: (NSString*) type
{
CFURLRef soundFileURLRef;
SystemSoundID soundFileObject;
CFBundleRef mainBundle;
mainBundle = CFBundleGetMainBundle ();
// Get the URL to the sound file to play
soundFileURLRef = CFBundleCopyResourceURL (mainBundle,
(CFStringRef)note,
(CFStringRef)type,
NULL);
// Create a system sound object representing the sound file
AudioServicesCreateSystemSoundID (soundFileURLRef, &soundFileObject);
AudioServicesPlaySystemSound (soundFileObject);
}
T开发者_Python百科hanks ,
You would need to call AudioServicesDisposeSystemSoundID
to clean up when you are done with the sound.
In your header:
@interface xyz
{
SystemSoundID soundFileObject;
};
in your .m file, create an init method (if you don't have one):
-(id)init
{
if ( (self = [super init]) )
{
AudioServicesCreateSystemSoundID (soundFileURLRef, &soundFileObject);
}
return self;
}
in your dealloc
-(void)dealloc
{
AudioServiceDisposeSystemSoundID(soundFileObject);
[super dealloc];
}
you should declare the soundFileURLRef also as a ivar.
精彩评论