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:
] error:nil]; [