Q: Add a sound that is controlled by main volume 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?

A: I would suggest checking out AVAudioPlayer. It works with the main volume and has other handy methods to adjust playback which you may take advantage of. 

A: As stated in the other answers you can use AVAudioPlayer for this. However, here is some sample code:
<AVAudioPlayerDelegate>

Be sure to include this ^^
- (void)myMethod{
        AVAudioPlayer *data;
        NSString *name = [[NSString alloc] initWithFormat:@"mySoundName"];
        NSString *source = [[NSBundle mainBundle] pathForResource:name ofType:@"mp3"];
        if (data) {
            [data stop];
            data = nil;
        }
        data=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: source] error:NULL];
        data.delegate = self;
        [data prepareToPlay];
                [data play];

}


A: As per this, you cannot change device volume programatically, however MPVolumeView (volume slider) is there to change device volume but only through user interaction.
AVAudioPlayer is there if you want application level volume. In this case you can use volume property to set your application volume (not device volume) programatically.
