我正在使用AVAudioPlayer
播放一个简短的wav文件。声音从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;
}
NSTimer
方法只调用[phoneCallPlayer play]
。在任何时候都无法以编程方式设置音量。有什么建议?感谢。
答案 0 :(得分:-1)
- (IBAction)volumeDidChange:(UISlider *)slider {
//Handle the slider movement
[audioPlayer setVolume:[slider value]];
}
应为滑块最小值0和最大值1。