Memory Leak on AudioServicesCreateSystemSoundID from bad conversion habits

July 6, 2009 § Leave a comment

Audio Toolbox Framework & AVFoundation Framework are the most popular audio frameworks to play audio. AudioQueue, part of Audio Toolbox Framework, requires you to manage buffers and byte level.

Mistakes you don’t want to make:

If you think you can convert the file format from .wav to .aif and then rename the extension from .aif to .caf, it may be just a hack and it’s not a good practice at all. This hack will cause a memory leak on the fuction of AudioServicesCreateSystemSoundID. This is something you don’t want to do in your code.

Proper way to convert files to .caf

afconvert -f caff -d ima4 input.wav output.caf

Audio Toolbox Framework

NSString *sound = @"sound";
NSString *path = [[NSBundle mainBundle] pathForResource:sound ofType:@"caf"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPathath], &soundID);
AudioServicesPlaySystemSound(soundID);

AVFoundation Framework

NSString *sound = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"mp3"];
Player =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:sound] error:nil];
[Player prepareToPlay];
[Player play];
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Memory Leak on AudioServicesCreateSystemSoundID from bad conversion habits at Web Builders.

meta

%d bloggers like this: