Reputation: 103
I have this code to play sounds:
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"audio2", CFSTR ("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
It works fine for an audio file that I have that is about 1 second long. It does not, however, work for one of my files that is about 4 minutes long. How can I fix this? They're both mp3 files and placed in the same directory.
Upvotes: 0
Views: 71
Reputation: 4884
According to the apple's doc, AudioServicesPlaySystemSound
has a limits as below:
Sound files that you play using this function must be:
- No longer than 30 seconds in duration
You can use AVAudioPlayer
instead.
Upvotes: 1