【发布时间】:2011-10-06 15:09:31
【问题描述】:
我正在尝试编写一个应用程序,该应用程序使用麦克风的平均功率来触发游戏响应。我在-init 中使用以下代码:
NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat: 44100.0], AVSampleRateKey, [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,il];
NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
if (recorder) {
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.03 target: self selector: @selector(myMethod:) userInfo: nil repeats: YES];
在我的方法中 float soundLevel=[录音机平均PowerForChannel:0];
触发在模拟器中工作正常,但当我将其放在手机上进行测试时无法正常工作。我做错了什么?
【问题讨论】:
-
这个解决方案帮助我让麦克风正常工作。 stackoverflow.com/questions/6350420/…
标签: xcode audio avaudioplayer