Some properties of avaudiorecorder (Sound Recorder)

Source: Internet
Author: User

1. Guide Frame

1. System Framework

Coreaudio.framework

Avfoundation.framework

2. header file

#import <AVFoundation/AVFoundation.h>

3. Compliance with agreements

<AVAudioRecorderDelegate>

{

Avaudiorecorder *_recoder; Recording

}

2. Recording

Record

First parameter: The URL where the recording location is converted into a string

NSString *path = Nshomedirectory ();

Use a string of the current date as the file name

NSDate *date = [NSDate Date];

NSDateFormatter *formatter = [[NSDateFormatter alloc]init];

Formatter.dateformat = @ "YYYYMMDDHHMMSS";

NSString *datestr = [Formatter stringfromdate:date];

NSString *path1 = [path stringbyappendingpathcomponent:[nsstring stringwithformat:@ "/DOCUMENTS/%@.CAF", DateStr]];

NSLog (@ "path1 =%@", path1);

Path = [path stringbyappendingpathcomponent:@ "/DOCUMENTS/1.CAF"];

NSLog (@ "path =%@", path);

Nsurl *url = [Nsurl Fileurlwithpath:path];

Second parameter: Recording related settings

Nsmutabledictionary *dict = [[Nsmutabledictionary alloc]init];

1. Set the recording format: Avformatidkey

[Dict Setobject:[nsnumber NUMBERWITHINT:KAUDIOFORMATLINEARPCM] forkey:avformatidkey];

2. Set recording sample rate: Avsampleratekey 8000/44100/96000

[Dict Setobject:[nsnumber numberwithint:44100] forkey:avsampleratekey];

3. Set recording quality: Avencoderaudioqualitykey

[Dict Setobject:[nsnumber Numberwithint:avaudioqualitylow] forkey:avencoderaudioqualitykey];

4. Set the number of linear sample bits: Avlinearpcmbitdepthkey 8/16/24

[Dict Setobject:[nsnumber numberwithint:16] forkey:avlinearpcmbitdepthkey];

5. Recording Channel: Avnumberofchannelskey 1/2

[Dict Setobject:[nsnumber Numberwithint:2] forkey:avnumberofchannelskey];

Avaudiosession *session = [[Avaudiosession alloc]init];

[Session Setcategory:avaudiosessioncategoryrecord Error:nil];

[Session Setactive:yes Error:nil];

if (!_recoder) {

_recoder = [[Avaudiorecorder alloc]initwithurl:url settings:dict Error:nil];

}

_recoder.delegate = self;

if ([_recoder Preparetorecord]) {

[_recoder Record];

}

Pause

[_recoder pause];

Stop

[_recoder stop];

3. Agreement

Avaudiorecorderdelegate related

-(void) audiorecorderdidfinishrecording: (Avaudiorecorder *) Recorder successfully: (BOOL) flag{

NSLog (@ "Finish");

}

-(void) Audiorecorderencodeerrordidoccur: (Avaudiorecorder *) Recorder error: (Nserror *) error{

NSLog (@ "error:%@", error);

}

-(void) Audiorecorderbegininterruption: (Avaudiorecorder *) recorder{

NSLog (@ "System-level interrupt start");

}

-(void) Audiorecorderendinterruption: (Avaudiorecorder *) Recorder withoptions: (nsuinteger) flags{

NSLog (@ "system-level Interrupt End");

Decide if you want to resume recording/playback after the end of the interruption

if (flags = = Avaudiosessioninterruptionoptionshouldresume) {

[_recoder Record];

}

Resume recording or playback

}

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.