I have a firing sound in the iOS app I’m developing, although at the moment the volume of the sound is controlled by the ringer volume, not the main volume. I thought it was because it was a .caf file, but after replacing it with an mp3 it did not change the volume type it is controlled with.
I think it is because I’m using AudioServicesCreateSystemSoundID, which I’m assuming applies only to the ringer volume.
- (IBAction)fire_rifle {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"rifle", CFSTR ("caf"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
How would I change this code so that the main volume is used instead of the ringer volume?
As stated in the other answers you can use
AVAudioPlayerfor this. However, here is some sample code:Be sure to include this ^^