I have two AVAudioPlayers, called ‘node’ and ‘zone’. They will sometimes be playing at the same time. When this happens I need to volume of ‘zone’ to fall to 0.2. When ‘node’ finishes, I need ‘zone’ to be returned to it’s original volume (pulled in from an array). I have an adjustPlayerVolume method and another method that sets a ‘nodeIsPlaying’ variable to false when the node has finished. both of these work fine.
the following code is being used to detect if the volume needs to go up or down or be left as it is. It is within a loop that runs for as long as the app is running.
NSLog(@"Zone Volume = %f", zonePlayer.volume);
if ((nodeIsPlaying == false) && (zonePlayer.volume <= 0.200000)) {
float maxVolume = [[[locationArray objectAtIndex:1] valueForKey:@"volume"] floatValue];
[self adjustZoneVolume:maxVolume];
NSLog(@"adjustZoneVolume called, node isn't playing and zonePlayer volume needs to be raised");
}
if ((nodeIsPlaying == true) && (zonePlayer.volume != 0.200000)) {
float maxVolume = 0.2;
[self adjustZoneVolume:maxVolume];
NSLog(@"adjustZoneVolume called, node is playing and zonePlayer volume needs to be lowered");
}
The log at the top consistently prints a volume of 0.200000 to the console.
When nodeIsPlaying is set to true, the bottom condition is returned, even though the NOT operator should prevent this from happening.
When nodeIsPlaying is set to false, nothing happens.
So there is something wrong with the <= and != operations.
Probably something really stupid…
Any ideas?
Thanks in advance.
For precision operations use NSDecimalNumber class.