我想問一個簡單的麥克風音量水平檢測問題。我的代碼只是正常的iOS 6或更低,但並不適用於iOS 7,我的代碼看起來是這樣的:麥克風不能在iOS 7上工作
-(void)viewDidLoad{
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
nil];
NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
if (recorder) {
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
} else{
NSLog([error description]);
}
}
// then call periodically with the following method, volumeLevelSampling
-(void)volumeLevelSampling{
[recorder updateMeters];
NSLog(@"Average input: %f Peak input: %f", [recorder averagePowerForChannel:0], [recorder peakPowerForChannel:0]);
}
它完美罰款在iOS 6中,但它不是抽樣的iOS 7的任何結果總是 - 120。
我遇到同樣的問題,當我在Settings.app檢查我的應用程序_is_授權使用話筒。 – Shizam
@EricPoon ...你能解決這個問題嗎?因爲我有一個應用程序,我無法錄製來自麥克風的聲音,但只能使用iPad Air和iOS 7. – Beto