Volume changes during AVAudioPlayer playback

心不动则不痛 提交于 2019-12-23 09:47:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!