Preload *.wav with SystemSoundID?
I am playing a wav file to give a little audio feedback when a button in my UI is pressed. My question is when you first press the button there is a delay (about 1.5secs) whilst the sound file "sound.wav" is loaded and cached. Is there a way to pre-cache this file (maybe in my viewDidLoad)? I guess I could do it by just playing it a viewDidLoad, but would really need to disable the audio so it does not "beeb" each time the app starts.
many thanks for and help.
gary
EDIT_001: Looks like my question is a duplicate of this post unless anyone has any new info? Maybe a way to turn the play volume down temporarily, unless the audio is cleared each time through the run loop.
EDIT_002: I am currently using SystemSoundID / AudioServices:
-(void)playButtonSound {
NSBundle *bundle = [NSBundle mainBundle];
NSString *soundPath = [bundle pathForResource:@"buttonClick_002" ofType:@"wa开发者_开发知识库v"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundPath], &soundID);
AudioServicesPlaySystemSound(soundID);
}
Use performSelectorInBackground:@selector(<A SELECTOR>)
when the view loads to load the wav file into memory. Then play the sound when needed ;)
Hope this helps!
In the end I actually found that using AVAudioPlayer allowed my to do the preload that I required using (see below) in viewDidLoad to do the preload:
[audioPlayer prepareToPlay];
and then using (see below) in the button methods where I needed the sound to play on demand.
[audioPlayer play];
gary
精彩评论