An instance of iOS development to resolve recordings

Source: Internet
Author: User

Import Frame:

#import <AVFoundation/AVFoundation.h>

Declaring Global variables:

@interface Viewcontroller () <AVAudioRecorderDelegate>

{

Avaudiorecorder *audiorecorder;

}

@end

*button == CGRectMake (+); [Button Settitle: @" TICK "     = [Uicolor Browncolor];    [Button addtarget:self action: @selector (Startaudiorecoder:) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:button];
trigger events for buttons- (void) Startaudiorecoder: (UIButton *) sender{sender.selected= !sender.selected; if(sender.selected! =YES)        {[Audiorecorder stop]; return; }        //url is local URL avaudiorecorder requires a stored pathNSString *name = [NSString stringWithFormat:@"%d.aiff",(int) [NSDate date].timeintervalsince1970]; NSString*path =[Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES). Firstobject    Stringbyappendingpathcomponent:name]; Nserror*error; //Recorder InitializationAudiorecorder = [[Avaudiorecorder alloc]initwithurl:[nsurl Fileurlwithpath:path] settings:@{avnumberofchannelskey:@2, avsampleratekey:@44100, avlinearpcmbitdepthkey:@ +, avencoderaudioqualitykey:@ (Avaudioqualitymax), avencoderbitratekey:@128000} error:&ERROR];    [Audiorecorder Preparetorecord];    [Audiorecorder Record]; Audiorecorder.Delegate=Self ; /*The 1.AVNumberOfChannelsKey channel number is typically a two-channel value of 2 2.AVSampleRateKey sampling rate unit Hz is usually set to 44100 that is 44.1k 3.AVLINEARPCMBITDEP Thkey bit rate 8 4.AVEncoderAudioQualityKey sound quality ①avaudioqualitymin = 0, minimum mass ②avaud Ioqualitylow = 0x20, lower quality ③avaudioqualitymedium = 0x40, intermediate mass ④avaudioqualityhigh = 0x60, High quality ⑤avaudioqualitymax = 0x7F Best quality 5.AVEncoderBitRateKey audio encoded bitrate unit Kbps transmission rate general Settings 128000 is 128KBP S*/NSLog (@"%@", path);} Proxy method:- (void) Audiorecorderdidfinishrecording: (Avaudiorecorder *) Recorder successfully: (BOOL) flag{NSLog (@"End of recording");//classes for file operationsNsfilemanager *manger =[Nsfilemanager Defaultmanager]; NSString*path =[Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES) lastobject];//get all the child files of the current file SubpathsatpathNsarray *pathllist =[Manger Subpathsatpath:path];//need to get only audio filesNsmutablearray *audiopathlist =[Nsmutablearray array];//Traverse all sub-files under this folder  for(NSString *audiopathinchpathllist) {//distinguish whether a file is recorded by comparing its extension name (extension suffix)if([Audiopath.pathextension isequaltostring:@"AIFF"]) {//Put the filtered files in the array[Audiopathlist Addobject:audiopath]; }} NSLog (@"%@", audiopathlist); }

An instance of iOS development to resolve recordings

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.