iphone - AVCapture Session and detecting blow from mic -
i trying record video avcapture session , same time detecting blow facing problem when click record button camera freezes., 1 importent thing when remove audio input avcapture session every thing working fine..how should handle this. should appreciable..
code recording button follows
[recordbutton setenabled:no]; nsurl *url = [nsurl fileurlwithpath:@"/dev/null"]; nsdictionary *settings = [nsdictionary dictionarywithobjectsandkeys: [nsnumber numberwithfloat: 44100.0], avsampleratekey, [nsnumber numberwithint: kaudioformatapplelossless], avformatidkey, [nsnumber numberwithint: 1], avnumberofchannelskey, [nsnumber numberwithint: avaudioqualitymax], avencoderaudioqualitykey, nil]; nserror *error; recorder = [[avaudiorecorder alloc] initwithurl:url settings:settings error:&error]; if (recorder) { [recorder preparetorecord]; recorder.meteringenabled = yes; [recorder record]; leveltimer = [nstimer scheduledtimerwithtimeinterval: 0.03 target: self selector: @selector(leveltimercallback:) userinfo: nil repeats: yes]; } else{ nslog(@"error%@",[error description]); } [recordbutton setimage:[uiimage imagenamed:@"record-h.png"] forstate:uicontrolstatenormal]; [timerlbl sethidden:false]; [lblhr sethidden:false]; [lblmnt sethidden:false]; [self togglerecording:nil]; startdate = [nsdate date] ; startdate = [[startdate datebyaddingtimeinterval:((-1)*(pausetimeinterval))] retain]; timer = [nstimer scheduledtimerwithtimeinterval:1.0/10.0 target:self selector:@selector(updatetimer) userinfo:nil repeats:yes]; } and code start recording [self togglerecording:nil]; follows
- (ibaction)togglerecording:(id)sender { // start recording if there isn't recording running. stop recording if there is. if ([uiimagepickercontroller issourcetypeavailable:sourcetype]) { if (![[[self capturemanager] recorder] isrecording]) [[self capturemanager] startrecording]; else [[self capturemanager] stoprecording]; } } i setting avcapture session follows
- (bool) setupsession { bool success = no; // set torch , flash mode auto if ([[self backfacingcamera] hasflash]) { if ([[self backfacingcamera] lockforconfiguration:nil]) { if ([[self backfacingcamera] isflashmodesupported:avcaptureflashmodeauto]) { [[self backfacingcamera] setflashmode:avcaptureflashmodeauto]; } [[self backfacingcamera] unlockforconfiguration]; } } if ([[self backfacingcamera] hastorch]) { if ([[self backfacingcamera] lockforconfiguration:nil]) { if ([[self backfacingcamera] istorchmodesupported:avcapturetorchmodeauto]) { [[self backfacingcamera] settorchmode:avcapturetorchmodeauto]; } [[self backfacingcamera] unlockforconfiguration]; } } // init device inputs avcapturedeviceinput *newvideoinput = [[avcapturedeviceinput alloc] initwithdevice:[self frontfacingcamera] error:nil]; avcapturedeviceinput *newaudioinput = [[avcapturedeviceinput alloc] initwithdevice:[self audiodevice] error:nil]; // setup still image file output avcapturestillimageoutput *newstillimageoutput = [[avcapturestillimageoutput alloc] init]; nsdictionary *outputsettings = [[nsdictionary alloc] initwithobjectsandkeys: avvideocodecjpeg, avvideocodeckey, nil]; [newstillimageoutput setoutputsettings:outputsettings]; [outputsettings release]; // create session (use default avcapturesessionpresethigh) avcapturesession *newcapturesession = [[avcapturesession alloc] init]; // add inputs , output capture session if ([newcapturesession canaddinput:newvideoinput]) { [newcapturesession addinput:newvideoinput]; } if ([newcapturesession canaddinput:newaudioinput]) { [newcapturesession addinput:newaudioinput]; } if ([newcapturesession canaddoutput:newstillimageoutput]) { [newcapturesession addoutput:newstillimageoutput]; } [self setstillimageoutput:newstillimageoutput]; [self setvideoinput:newvideoinput]; [self setaudioinput:newaudioinput]; [self setsession:newcapturesession]; [newstillimageoutput release]; [newvideoinput release]; [newaudioinput release]; [newcapturesession release]; // set movie file output nsurl *outputfileurl = [self tempfileurl]; avcamrecorder *newrecorder = [[avcamrecorder alloc] initwithsession:[self session] outputfileurl:outputfileurl]; [newrecorder setdelegate:self]; // send error delegate if video recording unavailable if (![newrecorder recordsvideo] && [newrecorder recordsaudio]) { nsstring *localizeddescription = nslocalizedstring(@"video recording unavailable", @"video recording unavailable description"); nsstring *localizedfailurereason = nslocalizedstring(@"movies recorded on device contain audio. accessible through itunes file sharing.", @"video recording unavailable failure reason"); nsdictionary *errordict = [nsdictionary dictionarywithobjectsandkeys: localizeddescription, nslocalizeddescriptionkey, localizedfailurereason, nslocalizedfailurereasonerrorkey, nil]; nserror *novideoerror = [nserror errorwithdomain:@"avcam" code:0 userinfo:errordict]; if ([[self delegate] respondstoselector:@selector(capturemanager:didfailwitherror:)]) { [[self delegate] capturemanager:self didfailwitherror:novideoerror]; } } [self setrecorder:newrecorder]; [newrecorder release]; success = yes; return success; }
i have googled , find solution here. using avcapturesession , avaudioplayer together
Comments
Post a Comment