IOS Recording (Avaudiorecorder)

Source: Internet
Author: User

#import "HMViewController.h"#import<AVFoundation/AVFoundation.h>@interfaceHmviewcontroller ()-(ibaction) Startrecord;-(ibaction) Stoprecord; @property (nonatomic, strong) Avaudiorecorder*Recorder, @property (nonatomic, strong) Cadisplaylink*timer; @property (nonatomic, strong) Nstimer*Stoprecordtimer;/** Duration of silence*/@property (nonatomic, assign) cgfloat slientduration;@end@implementationHmviewcontroller- (void) viewdidload{[Super Viewdidload]; }- (void) addtimer{Self.timer=[Cadisplaylink displaylinkwithtarget:self selector: @selector (update)]; [Self.timer Addtorunloop:[nsrunloop Mainrunloop] formode:nsrunloopcommonmodes];}- (void) removetimer{[Self.timer invalidate]; Self.timer=Nil;}- (void) update{//Update test Values[Self.recorder updatemeters]; //If the decibel does not exceed -20    floatPower = [Self.recorder Averagepowerforchannel:0]; if(Power <=- -) {//almost muteSelf.slientduration + =self.timer.duration; if(Self.slientduration >=2) {            //Stop Recording[Self.recorder stop]; }    } Else{//have a talkSelf.slientduration =0; }}//-(void) Update//{//    //Update test Values//[Self.recorder updatemeters];//    //    //If the decibel does not exceed -20//float power = [Self.recorder averagepowerforchannel:0];//if (Power <= -20) {//almost mute//if (!self.stoprecordtimer) {//Self.stoprecordtimer = [Nstimer scheduledtimerwithtimeinterval:2.0 target:self.recorder selector: @selecto R (Stoprecord) Userinfo:nil Repeats:no];//        }//} else {//have a talk////[Self.stoprecordtimer invalidate];////Self.stoprecordtimer = nil;//nsdate *time = [NSDate datewithtimeintervalsincenow:2.0];//[Self.stoprecordtimer setfiredate:time];//    }//}-(ibaction) startrecord {nsstring*doc =[Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) lastobject]; NSString*path = [Doc stringbyappendingpathcomponent:@"TEST.CAF"]; Nsurl*url =[Nsurl Fileurlwithpath:path]; Avaudiorecorder*recorder =[[Avaudiorecorder alloc] Initwithurl:url settings:nil Error:nil]; //Buffering[Recorder Preparetorecord]; //turn on the decibel measurement functionrecorder.meteringenabled =YES; //Start Recording[recorder record]; Self.recorder=Recorder; //Turn on Timer[self addtimer];}-(ibaction) Stoprecord {//[Self.recorder stop];}@end

IOS Recording (Avaudiorecorder)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.