2012-10-31 58 views
0

在我更新iOS 6的应用程序后,AVAudioRecorder在设备上不起作用,并在模拟器上[soundRecorder prepareToRecord]中崩溃。AVAudioRecorder在iOS6更新后无法工作

UPD:用后[soundRecorder record];

没有延迟有谁找到了一些修复audioRecorderDidFinishRecording:successfully:委托方法火灾?

- (IBAction)recordSound { 
    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; 
    [appDelegate.audioPlayer stop]; 
    appDelegate.audioPlayer = nil; 

    [self stopPlaying]; 

    if (soundRecorder.recording) { 
     [soundRecorder stop]; 
     soundRecorder = nil; 
     [timer invalidate]; 
     timer = nil; 
     NSError *error; 
     [[AVAudioSession sharedInstance] setActive: NO error: &error]; 
     NSLog([error localizedDescription]); 
    }else{ 
     NSManagedObject *oldSound = _sight.sound; 
     if (oldSound != nil) { 
      [__managedObjectContext deleteObject:oldSound]; 
     } 
     [self saveContext]; 

     if (!soundRecorder) 
     { 
      NSError *errorAudioSession; 
      [[AVAudioSession sharedInstance] 
      setCategory: AVAudioSessionCategoryPlayAndRecord 
      error: &errorAudioSession]; 
      NSLog([errorAudioSession description]); 

      NSDictionary *recordSettings = 
      @{AVFormatIDKey: @(kAudioFormatMPEG4AAC), 
     AVNumberOfChannelsKey: @1, 
     AVEncoderAudioQualityKey: @(AVAudioQualityMedium)}; 

      NSError *error; 
      AVAudioRecorder *newRecorder = 
      [[AVAudioRecorder alloc] initWithURL: soundFileURL 
             settings: recordSettings 
              error: &error]; 
      NSLog([error description]); 
      soundRecorder = newRecorder; 
      soundRecorder.delegate = self; 

     } 

     [soundRecorder stop]; 
     [soundRecorder prepareToRecord]; 
     [soundRecorder record]; 
     timer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(updateRecordStatus) userInfo:nil repeats:YES]; 

    } 
} 
+0

它在崩溃时打印什么错误? – Kevin

+0

我现在已经检查过了,只有在Simulator中的所有异常中启用了断点才会发生崩溃,否则在没有任何错误消息的情况下它不会正常工作。 – Shmidt

+0

P.S.一切工作正常iOS5 – Shmidt

回答

0

我有录音为即将结束的一个问题,因为我告诉了在iOS6的第一次开始录制后(在iOS5中伟大的工作)。 问题是我设置AVAudioRecorder的委托,但在iOS6 AVAudioSession的委托已弃用,删除委托让我的应用程序再次工作。

http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVAudioSession_ClassReference/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instp/AVAudioSession/delegate

编辑:为@Flink问。我有一个用于录制音频的包装类(只扩展NSObject),它使用AVAudioRecorder。代码的相关部分如下:

... 
NSError *error = nil; 
audioRecorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error]; 
//the relevant part of code is this "if" 
if(SYSTEM_VERSION_LESS_THAN(@"6") && delegate){ 
    audioRecorder.delegate = self.delegate; 
} 

BOOL ok = [audioRecorder prepareToRecord]; 

if (ok){ 
    if(duration){ 
    ok = [audioRecorder recordForDuration:duration]; 
    } 
    else { 
    ok = [audioRecorder record]; 
    } 

    if(!ok) { 
    LogError(...); 
    }else { 
    LogInfo(@"recording"); 
    }    
}else { 
    LogError(...);  
} 
... 
+0

如果你可以粘贴更新的AVAudioRecorder代码:) – Shmidt

相关问题