Change volume during AVAudioPlayer playback

I play a short wav file using AVAudioPlayer. Sound is played every two seconds using the method NSTimer. The first time you play the sound, the volume is thin, but in subsequent games, the volume is so low that you can hardly hear it. Sometimes a drop in volume occurs halfway through the first game. This happens on the iPad 3, so choosing speakers is not a problem.

NSError *phoneCallError;
NSURL *phoneCallUrl = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/phone-calling-1.wav", [[NSBundle mainBundle] resourcePath]]];
AVAudioPlayer *phoneCallPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:phoneCallUrl error:&phoneCallError];
if (phoneCallError) {
    NSLog(@"%@: %@", self, phoneCallError);
} else {
    phoneCallPlayer.numberOfLoops = 0;
}

The method NSTimerjust calls [phoneCallPlayer play]. The software level is not installed. Any suggestions? Thank.

+5
source share
1 answer
- (IBAction)volumeDidChange:(UISlider *)slider {
//Handle the slider movement
[audioPlayer setVolume:[slider value]];

}

there must be a minimum value of the slider 0 and a maximum of 1.

-1
source

All Articles