小编Eri*_*oon的帖子

麦克风无法在iOS 7上运行

我想问一下简单的麦克风音量检测问题.我的代码适用于iOS 6或更低版本,但不适用于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]);


}
Run Code Online (Sandbox Code Playgroud)

它在iOS 6中运行得非常好,但它在iOS 7中没有采样任何东西.结果总是-120.

ios ios7

7
推荐指数
2
解决办法
5765
查看次数

标签 统计

ios ×1

ios7 ×1