AVAudioPlayer播放期间的音量变化

AVAudioPlayer播放期间的音量变化

本文介绍了AVAudioPlayer播放期间的音量变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AVAudioPlayer播放简短的wav文件.从NSTimer方法每隔几秒钟重播一次声音.第一次播放声音时,音量很好,但在随后的播放中,音量太低,几乎听不到声音.有时音量会在第一次播放的中间发生.这是在iPad 3上发生的,因此扬声器的选择不是问题.

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;
}

NSTimer方法仅调用[phoneCallPlayer play].不会以编程方式设置音量.有什么建议?谢谢.

The NSTimer method just calls [phoneCallPlayer play]. At no time is the volume set programmatically. Any suggestions? Thanks.

推荐答案

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

}

应为滑块的最小值0和最大值1.

should be slider minimum value 0 and maximum 1.

这篇关于AVAudioPlayer播放期间的音量变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 01:50