[英]Why does averagePowerForChannel always return -160?
I have these code and both method call are SUCCESS. 我有这些代码,并且两个方法调用均成功。
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: NULL];
[audioSession setActive: YES error: NULL];
And these code to start recording: 然后这些代码开始记录:
[self.recorder prepareToRecord];
[self.recorder recordForDuration: 60];
I have a timer function to update meters 我有计时器功能来更新仪表
- (void)updateMeters
{
[self.recorder updateMeters];
float peakPower = [self.recorder averagePowerForChannel: 0];
double ALPHA = 0.05;
double peakPowerForChannel = pow(10, (ALPHA * peakPower));
self.recordView.progress = peakPowerForChannel;
NSLog(@"%f", peakPower);
}
But I do not know why peakPower is always 160. I have another demo(from web) can work well, but I can not find any difference between them. 但是我不知道为什么peakPower总是160。我有另一个演示(来自Web)可以很好地工作,但是我发现它们之间没有任何区别。
只需尝试设置:
recorder.meteringEnabled = YES;
Set the category to AVAudioSessionCategoryPlayAndRecord
and check 将类别设置为
AVAudioSessionCategoryPlayAndRecord
并检查
NSError *error;
[[AVAudioSession sharedInstance]
setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
if (error) {
NSLog(@"Error description: %@", [error description]);
}
奇怪的是[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: &err]
和[[AVAudioRecorder alloc] initWithURL: [NSURL fileURLWithPath: self.recordPath] settings: recordSetting error: NULL]
必须具有相同的功能...这就是答案题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.