开发者

IOS AVAudioRecorder updatemeters seems not update on device, works on simulator

开发者 https://www.devze.com 2023-02-07 22:33 出处:网络
bool b; NSLog(@\"url\"); NSURL *url = [NSURL fileURLWithPath:@\"/dev/null\"]; NSLog(@\"dizionario\"); NSDictionary *audioSettings = [NSDictionary开发者_StackOverflow社区 dictionaryWithObjectsAndKeys:
bool b;
NSLog(@"url");
NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];
NSLog(@"dizionario");
NSDictionary *audioSettings = [NSDictionary开发者_StackOverflow社区 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]); 
 }  

and

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

the mic detects the firs found (i think) because every new runs the value displayed is different, but on the same run the value is not changing at all any ideas?


found the solution. with audioSession = [[AVAudioSession sharedInstance] retain]; [audioSession setCategory:AVAudioSessionCategoryRecord error: nil]; [audioSession setActive:YES error: nil];

0

精彩评论

暂无评论...
验证码 换一张
取 消