我正在做一个可以录制声音的项目。
为了录制音频,我使用了EZAudio库,该库可以让我看到波形。
依次将ViewController中的对象插入到UINavigationController中,但是不幸的是,当我回来时,我得到了EXC_BAD_ACCESS,我不知道如何解决...
我认为问题是UINavigationController ...

这是代码接口(interface):

#import <UIKit/UIKit.h>
#import "EZAudio.h"
#import <AVFoundation/AVFoundation.h>



    @interface AudioViewController : UIViewController<AVAudioPlayerDelegate, EZMicrophoneDelegate>
    {

    }
    @property (nonatomic, weak) IBOutlet EZAudioPlotGL *plotGL;
    @property (nonatomic,assign) BOOL isRecording;
    @property (nonatomic,retain) EZMicrophone *microphone;
    @property (nonatomic,retain) EZRecorder *recorder;
    @property (nonatomic,retain) IBOutlet UIButton *buttonRecorder;

    -(IBAction)recordingAudio:(id)sender;

    @end

这是代码实现:
@implementation AudioViewController
@synthesize plotGL, isRecording, microphone, recorder, buttonRecorder;

-(void)toggleRecording:(id)sender{

}


-(void)recordingAudio:(id)sender{
    if(self.isRecording == YES){
        self.isRecording = NO;
    }
    else{
        self.isRecording = YES;
    }
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.


    //Inizializzo il microfono
    self.microphone = [EZMicrophone microphoneWithDelegate:self];

    self.plotGL.backgroundColor = [UIColor whiteColor];
    self.plotGL.color           = [UIColor yellowColor];
    self.plotGL.plotType        = EZPlotTypeBuffer;

    self.plotGL.shouldFill      = NO;
    self.plotGL.shouldMirror    = NO;

    [self.microphone startFetchingAudio];




    NSArray *syms = [NSThread  callStackSymbols];
    if ([syms count] > 1) {
        NSLog(@"<%@ %p> %@ - caller: %@ ", [self class], self, NSStringFromSelector(_cmd),[syms objectAtIndex:1]);
    } else {
        NSLog(@"<%@ %p> %@", [self class], self, NSStringFromSelector(_cmd));
    }

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

-(void)microphone:(EZMicrophone *)microphone
 hasAudioReceived:(float **)buffer
   withBufferSize:(UInt32)bufferSize
    withNumberOfChannels:(UInt32)numberOfChannels {
    dispatch_async(dispatch_get_main_queue(),^{

        [self.plotGL updateBuffer:buffer[0] withBufferSize:bufferSize];
    });
}

-(void)microphone:(EZMicrophone *)microphone hasAudioStreamBasicDescription:(AudioStreamBasicDescription)audioStreamBasicDescription {

    [EZAudio printASBD:audioStreamBasicDescription];
    self.recorder = [EZRecorder recorderWithDestinationURL:[self getAudioFile]
                                           andSourceFormat:audioStreamBasicDescription];
}

-(void)microphone:(EZMicrophone *)microphone
    hasBufferList:(AudioBufferList *)bufferList
   withBufferSize:(UInt32)bufferSize
withNumberOfChannels:(UInt32)numberOfChannels {

    if( self.isRecording ){
        [self.recorder appendDataFromBufferList:bufferList
                                 withBufferSize:bufferSize];
    }

}

#pragma mark - AVAudioPlayerDelegate
-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
    [self.microphone stopFetchingAudio];
}



#pragma mark - Utility
-(NSArray*)applicationDocuments {
    return NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
}

-(NSString*)applicationDocumentsDirectory
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    NSLog(@"basePath %@",basePath);
    return basePath;
}

-(NSURL*)getAudioFile {

    NSString *fileName = @"audio.wav";
    return [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@",[self applicationDocumentsDirectory],fileName]];
}

@end

最佳答案

请插入:

(nonatomic, weak) IBOutlet EZAudioPlotGL *plotGL; ---> ...(nonatomic, retain) IBOutlet EZAudioPlotGL *plotGL;

关于ios - EZ麦克风EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21086888/

10-13 09:27