问题
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.
回答1:
Just try to set:
recorder.meteringEnabled = YES;
回答2:
Set the category to AVAudioSessionCategoryPlayAndRecord and check
NSError *error;
[[AVAudioSession sharedInstance]
setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
if (error) {
NSLog(@"Error description: %@", [error description]);
}
回答3:
It is strange that [audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: &err] and [[AVAudioRecorder alloc] initWithURL: [NSURL fileURLWithPath: self.recordPath] settings: recordSetting error: NULL] must in the same function...It is the answer of this question.
来源:https://stackoverflow.com/questions/24991908/why-does-averagepowerforchannel-always-return-160