Reanimation Reanimation - 1 year ago 104
iOS Question

Lower volume of AVAudioPlayer sound

I have a background song that I use on an infinite loop while my app is in use.
Except that the sound/volume is too high... I'd like it to be played at half the volume... This is how I load the music:

//background music for in-game loop
backgroundLoop = [[NSBundle mainBundle] pathForResource:@"Background" ofType:@"wav"];
GameMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:backgroundLoop] error:NULL];
GameMusic.delegate = self; //need <...> in .h
GameMusic.numberOfLoops = -1; //play infinite loop

I've tried a few things, but nothing affects the volume of the track. I've tried this:

GameMusic.volume = 0.5f;


[GameMusic setVolume: 0.5f];

but it doesn't change the volume and still plays at the same max volume...

The strange thing is, if I set the volume to 0.0 (
[GameMusic setVolume: 0.5f];
) it doesn't play at all because I'm guessing it's setting volume to zero... but why does
not adjust the volume when it's a linear scale from 0-1?

How can I lower the volume of the sound? It's far too loud.

Also, I tried editing the actual sounds in Garageband, but they won't export any sounds under a second long so it's not feasible to adjust them manually.



A Wiki, shows the following file formats are supported:

- AAC (MPEG-4 Advanced Audio Coding)
- ALAC (Apple Lossless)
- AMR (Adaptive Multi-rate)
- HE-AAC (MPEG-4 High Efficiency AAC)
- iLBC (internet Low Bit Rate Codec)
- Linear PCM (uncompressed, linear pulse code modulation)
- MP3 (MPEG-1 audio layer 3)
- ยต-law and a-law

Unfortunately, I changed my
to a
and it still isn't working :(

Answer Source

I suspect that it is working but, because the sound is so loud to start with, you are not perceiving the difference (because of the logarithmic nature of the decibel scale of intensities). Try a much smaller number, such as 0.05, perhaps.