更新到iOS5录像机不再有效



我有一个应用程序一直工作,直到我在设备上安装了ios5。这是代码

UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
    AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);    
    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
    AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
    //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;    
    bool b;

    //NSLog(@"audio");
    recorder = [[AVAudioRecorder alloc] initWithURL:url settings:audioSettings error:&error];
    //NSLog(@"audio");
    if (recorder) {
        //NSLog(@"prepara");
        b=[recorder prepareToRecord];
        //NSLog(@"%@",(b ? @"OK" : @"NO"));
        //NSLog(@"meter");
        recorder.meteringEnabled = YES;
        //NSLog(@"recorder");
        b=[recorder record];
        //NSLog(@"%@", (b ? @"OK" : @"NO"));            
        //        NSLog(@"leveltimer");
        //        levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.03 target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES];
    } else {
        NSLog(@"************** ERRORE: ****************");
        NSLog([error description]);    
    }

的结果是,记录器记录沉默,没有峰值功率,没有平均功率。我用的是xcode4 (ios的inxcode4还是4.3,我还没有下载最新的xcode)为什么在ios5中不再工作了?不兼容?由于

我已经下载了最新的xcode,尝试

文件或缓存代替/dev/null,但没有运气

我已经解决了,但不知道为什么它不工作了。

上面的代码放在一个单例类中,在应用程序开始时加载并初始化一次。

似乎只记录一个语音电源然后停止(即使我已经控制了记录=真,计量启用=真ecc…在日志)

现在我已经把相同的代码在一个方法的单例类和调用该方法从文件的屏幕"ingame"和工作…

嗯……知道为什么会这样吗?

用以下代码替换url路径:

NSString *documentsDirectory = [nssearchpathfordirectortoriesindomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];NSString *filepath = [documentsDirectory stringByAppendingPathComponent:@"Files"];

NSURL *url = [NSURL fileURLWithPath:filepath];

最新更新