iphone - Voice recorder view. It stops recording when I go to another view, help? -


ok right recordviewcontroller, allows use voice function , record. functions properly, when press 'back' button , go different view recording stops. how make keeps recording, user can record voice whilst on different views?

@implementation recordviewcontroller @synthesize actspinner, btnstart, btnplay;    -(void)countup {      mainint += 1;     seconds.text = [nsstring stringwithformat:@"%02d", mainint];  }  -(ibaction)goback:(id)sender; {      [self dismissmodalviewcontrolleranimated:yes]; }    /*  // designated initializer. override perform setup required before view loaded.  - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil {  if (self = [super initwithnibname:nibnameornil bundle:nibbundleornil]) {  // custom initialization  }  return self;  }  */  /*  // implement loadview create view hierarchy programmatically, without using nib.  - (void)loadview {  }  */    // implement viewdidload additional setup after loading view, typically nib. - (void)viewdidload {     [super viewdidload];      //start toggle in true mode.     toggle = yes;     btnplay.hidden = yes;      //instanciate instance of avaudiosession object.     avaudiosession * audiosession = [avaudiosession sharedinstance];     //setup audiosession playback , record.      //we use record , switch playback leter,     //since going both lets set once.     [audiosession setcategory:avaudiosessioncategoryplayandrecord error: &error];     //activate session     [audiosession setactive:yes error: &error];  }    /*  // override allow orientations other default portrait orientation.  - (bool)shouldautorotatetointerfaceorientation:(uiinterfaceorientation)interfaceorientation {  // return yes supported orientations  return (interfaceorientation == uiinterfaceorientationportrait);  }  */  - (ibaction)  start_button_pressed{       if(toggle)     {         toggle = no;         [actspinner startanimating];         [btnstart setimage:[uiimage imagenamed:@"stoprecordingbutton.png"] forstate:uicontrolstatenormal];         mainint = 0;         thetimer = [nstimer scheduledtimerwithtimeinterval:1.0 target:self selector:@selector(countup) userinfo:nil repeats:yes];           btnplay.enabled = toggle;         btnplay.hidden = !toggle;          //begin recording session.         //error handling removed.  please add own code.          //setup dictionary object recording settings          //recording sessoin use         //its not clear me of these required , bare minimum.         //this resource: http://www.totodotnet.net/tag/avaudiorecorder/         nsmutabledictionary* recordsetting = [[nsmutabledictionary alloc] init];         [recordsetting setvalue :[nsnumber numberwithint:kaudioformatappleima4] forkey:avformatidkey];         [recordsetting setvalue:[nsnumber numberwithfloat:44100.0] forkey:avsampleratekey];          [recordsetting setvalue:[nsnumber numberwithint: 2] forkey:avnumberofchannelskey];          //now have our settings going instanciate instance of our recorder instance.         //generate temp file use recording.         //this sample 1 found online , seems choice making tmp file         //will not overwrite existing one.         //i know mess of collapsed things 1 call.  can break out if need be.         recordedtmpfile = [nsurl fileurlwithpath:[nstemporarydirectory() stringbyappendingpathcomponent: [nsstring stringwithformat: @"%.0f.%@", [nsdate timeintervalsincereferencedate] * 1000.0, @"caf"]]];         nslog(@"using file called: %@",recordedtmpfile);         //setup recorder use file , record it.         recorder = [[ avaudiorecorder alloc] initwithurl:recordedtmpfile settings:recordsetting error:&error];         //use recorder start recording.         //im not sure why set delegate self yet.           //found in antother example, im fuzzy on still.         [recorder setdelegate:self];         //we call start recording process , initialize          //the subsstems when "record" starts right away.         [recorder preparetorecord];         //start actual recording         [recorder record];         //there optional method doing recording limited time see          //[recorder recordforduration:(nstimeinterval) 10]      }     else     {         toggle = yes;         [actspinner stopanimating];         [btnstart setimage:[uiimage imagenamed:@"recordbutton.png"] forstate:uicontrolstatenormal];         btnplay.enabled = toggle;         btnplay.hidden = !toggle;         [thetimer invalidate];          nslog(@"using file called: %@",recordedtmpfile);         //stop recorder.         [recorder stop];     } }  - (void)didreceivememorywarning {     // releases view if doesn't have superview.     [super didreceivememorywarning];      // release cached data, images, etc aren't in use. }  -(ibaction) play_button_pressed{      //the play button pressed...      //setup avaudioplayer play file recorded.     avaudioplayer * avplayer = [[avaudioplayer alloc] initwithcontentsofurl:recordedtmpfile error:&error];     [avplayer preparetoplay];     [avplayer play];  }  - (bool)shouldautorotatetointerfaceorientation:(uiinterfaceorientation)interfaceorientation {     // return yes supported orientations     return (interfaceorientation == uiinterfaceorientationlandscapeleft || interfaceorientation == uiinterfaceorientationlandscaperight); }  - (void)viewdidunload {     // release retained subviews of main view.     // e.g. self.myoutlet = nil;     //clean temp file.     nsfilemanager * fm = [nsfilemanager defaultmanager];     [fm removeitematpath:[recordedtmpfile path] error:&error];     //call dealloc on remaining objects.     [recorder dealloc];     recorder = nil;     recordedtmpfile = nil; }  - (void)dealloc {     [super dealloc]; }  @end 

thanks

keep reference somewhere in app (like in delegate) won't de-allocated.


Comments