mercredi 6 mai 2015

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;

and:

[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 0.1f or 0.5f 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.

Thanks.

Aucun commentaire:

Enregistrer un commentaire