在AVAudioRecorder上崩溃

时间:2014-01-13 21:29:00

标签: objective-c avaudiorecorder

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

工作正常。然后突然app录制结束后崩溃了。一旦它崩溃,然后下次如果我重新启动应用程序,它会继续发出类似的崩溃

我在操作员控制台中获得的一个消息是 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文件编写的,它有两个按钮来记录和播放

在app delegate中,我有

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");
                }

    }

}

0 个答案:

没有答案