AVAudioPlayer播放期间的音量更改

mjt*_*tus 5 objective-c avaudioplayer

我正在播放一个简短的wav文件AVAudioPlayer.声音每隔几秒钟从一个NSTimer方法重放一次.第一次播放声音时,音量很好,但在随后播放时,音量很低,几乎听不见.在第一场比赛中途偶尔会出现音量下降.这种情况发生在iPad 3上,因此扬声器的选择不是问题.

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;
}
Run Code Online (Sandbox Code Playgroud)

NSTimer方法只是调用[phoneCallPlayer play].在任何时候都无法以编程方式设置音量.有什么建议?谢谢.

Har*_*ngh -1

- (IBAction)volumeDidChange:(UISlider *)slider {
//Handle the slider movement
[audioPlayer setVolume:[slider value]];
Run Code Online (Sandbox Code Playgroud)

}

应为滑块最小值 0 和最大值 1。