Objective c AVAudioRecorder上的崩溃

Objective c AVAudioRecorder上的崩溃,objective-c,avaudiorecorder,Objective C,Avaudiorecorder,我在多个地方的项目中使用AVAudioSession。我还使用AVAudioRecorder录制声音,使用AVAudioPlayer播放声音。 记录 它工作得很好。录制完成后,应用程序突然崩溃。一旦它崩溃了,下一次如果我重新启动应用程序,它就会继续出现类似的崩溃 我在操作员控制台中得到的消息之一是 AddPropertyListenerImp发布消息以终止mediaserverd 0 有时,它是给予 AudioQueuePrime发布消息以杀死mediaserverd 我真的被这一点困住了。我不

我在多个地方的项目中使用AVAudioSession。我还使用AVAudioRecorder录制声音,使用AVAudioPlayer播放声音。 记录

它工作得很好。录制完成后,应用程序突然崩溃。一旦它崩溃了,下一次如果我重新启动应用程序,它就会继续出现类似的崩溃

我在操作员控制台中得到的消息之一是 AddPropertyListenerImp发布消息以终止mediaserverd 0

有时,它是给予 AudioQueuePrime发布消息以杀死mediaserverd

我真的被这一点困住了。我不知道该怎么办。请帮帮我

这是录音用的

NSDictionary *recordSettings = [NSDictionary
                                    dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithInt:kAudioFormatLinearPCM],AVFormatIDKey,
                                   [NSNumber numberWithInt:16],AVEncoderBitRateKey,
                                    [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
                                    [NSNumber numberWithFloat:8000.0],AVSampleRateKey,  
                                    [NSNumber numberWithInt:16], AVLinearPCMBitDepthKey,
                                    [NSNumber numberWithInt:AVAudioQualityHigh],AVEncoderAudioQualityKey,

                                    nil];

audioRecorder = [[AVAudioRecorder alloc]
                     initWithURL:soundFileURL
                     settings:recordSettings
                     error:&error];

 audioRecorder.delegate = self;


 [[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryRecord error:&error];

    if (error)
    {
        if(DEBUG)NSLog(@"error: %@", [error localizedDescription]);

    } else {
        [audioRecorder prepareToRecord];
    }
 if (!audioRecorder.recording)
    {

               [audioRecorder record];

       }

 if (!audioRecorder.recording)
    {
      NSError *error;


        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

        NSString *documentsDirectory = [paths objectAtIndex:0];


        NSString *file = [NSString stringWithFormat:@"%@/%@", documentsDirectory,filename];

        audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:file]   error:&error];



        audioPlayer.delegate = self;
        [audioPlayer setVolume:1.0];
        if (error)
        {
            if(DEBUG)NSLog(@"Error: %@",[error localizedDescription]);
        }
        else
        {
            [audioPlayer play];
                }
     }
这部分是在View Controller.m文件中编写的,该文件有两个按钮用于录制和播放

应用程序内代理,我有

AVAudioSession *session = [ AVAudioSession sharedInstance ];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(HeadsetAvailable:) name:AVAudioSessionRouteChangeNotification object:session];


-(void) HeadsetAvailable :(NSNotification *)notification
{

    NSArray *outputs = [[AVAudioSession sharedInstance] currentRoute].outputs;

    NSString *portName = [[outputs objectAtIndex:0] portName];

    if ([portName isEqualToString:@"Headphones"]) {
        NSLog(@"EventName=Headset&status=pluggedin");

    }
    else{
        NSLog(@"EventName=Headeset&status=unplugged");
                }

    }

}

请显示您的代码。添加了要录制和播放的代码