簡體   English   中英

EZ麥克風EXC_BAD_ACCESS

[英]EZMicrophone EXC_BAD_ACCESS

我正在制作一個可以錄制聲音的項目。 為了錄制音頻,我使用了EZAudio庫,該庫可以讓我看到波形。 ViewController中的對象又插入了UINavigationController中,但是不幸的是,當我回來時,我得到了EXC_BAD_ACCESS,我不知道如何解決...我認為問題是UINavigationController ...

這是代碼接口:

#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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM