2011-01-31 88 views
1
bool b; 
NSLog(@"url"); 
NSURL *url = [NSURL fileURLWithPath:@"/dev/null"]; 
NSLog(@"dizionario"); 
NSDictionary *audioSettings = [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:audioSettings error:&error]; 
NSLog(@"audio"); 
if (recorder) { 
[recorder prepareToRecord]; 
recorder.meteringEnabled = YES; 
b=[recorder record]; 
} else { 
NSLog(@"ERRORE:"); 
NSLog([error description]); 
} 

IOS AVAudioRecorder updatemeters似乎不是在设备更新,工作在模拟器

[recorder updatemeters]; 
NSLog(@"%f",[recorder peakPowerForChannel:0]); 

麦克风检测发现冷杉(我认为),因为每一个新的运行显示的值是不同的,但在同一运行的价值是不是完全改变 有什么想法?

回答

1

找到解决方案。 with audioSession = [[AVAudioSession sharedInstance] retain]; [audioSession setCategory:AVAudioSessionCategoryRecord error:nil]; [audioSession setActive:YES error:nil];