Вопрос

I want to preload a *.wav file in my app since it is rather large. I want to start loading it in viewcontroller1 and then play it in viewcontroller15. I need the code to preload it; the code for playing it is:

CFBundleRef mainbundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef =CFBundleCopyResourceURL(mainbundle, (CFStringRef) @"america", CFSTR ("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
Это было полезно?

Решение

preloading a wav file's header requires reading a very small amount of data. this will be enough to initialize your audio playback stream. you would also need to then fill your playback buffers (a rather small amount of data to read) to begin playback.

to preload an audio file's sample data, you can use AudioFile* APIs, and custom I/O callbacks.

however, the scenario you describe is a good example of when not to preload an audio file's sample data.

a wav file can be streamed from disk in real time. it does not need to read the entire file's sample data before playing. loading large audio files into memory is unnecessary for realtime playback. of course, iOS devices also have low memory ceilings.

if preloading and initializing the stream is what you want, you can use ExtAudioFile* APIs and still stream using an API such as AudioQueue*.

some more detail about the problem you are facing may help. i don't see any good reason to preload an audio file's sample data in this case; only negative side effects.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top