问题
I am playing a short wav file using AVAudioPlayer
. The sound is replayed every couple of seconds from an NSTimer
method. The first time the sound is played, the volume is fine but on subsequent plays the volume is so low that it is almost inaudible. Occasionally the volume drop occurs halfway through the first play. This is happening on an iPad 3, so speaker selection isn't an issue.
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 NSTimer
method just calls [phoneCallPlayer play]
. At no time is the volume set programmatically. Any suggestions? Thanks.
回答1:
- (IBAction)volumeDidChange:(UISlider *)slider {
//Handle the slider movement
[audioPlayer setVolume:[slider value]];
}
should be slider minimum value 0 and maximum 1.
来源:https://stackoverflow.com/questions/12014578/volume-changes-during-avaudioplayer-playback