About recording under iOS

Source: Internet
Author: User

http://blog.csdn.net/silencetq/article/details/8447400

I'm using the Avaudiorecorder framework to do the recording.

This recording is somewhat different from the Speakhere on the official website, the biggest difference is that this must be recorded to finish processing the file, while the Speakhere example is a way to achieve the effect of side recording side uploads.

#import <AVFoundation/AVFoundation.h>

#import <CoreAudio/CoreAudioTypes.h>

Introducing the framework, which is the basic equipment for using the recording function

First of all, the default Avaudiorecorder format after recording is. CAF, and most of the players are not supported in this format, the following paragraph is a format that allows the recording format to be WAV

Nsdictionary *recordsetting = [[nsdictionary alloc] initwithobjectsandkeys:

[nsnumber numberwithfloat: 44100.0],avsampleratekey,//Sample rate

[nsnumber numberwithint: kaudioformatlinearpcm],avformatidkey,

[nsnumber numberwithint: +],avlinearpcmbitdepthkey,//sample number of digits default

[nsnumber Numberwithint: 2], number of avnumberofchannelskey,//channels

[nsnumber numberwithbool:NO],avlinearpcmisbigendiankey,//big or small end is the way memory is organized

[nsnumber numberwithbool:NO],Avlinearpcmisfloatkey,nil];//whether the sampled signal is an integer or a floating-point number

Nsurl *recordedtmpfile = [nsurl fileurlwithpath: [Nstemporarydirectory() stringByAppendingPathComponent: [nsstring stringwithformat: @ "%.0f.%@", [nsdate  Timeintervalsincereferencedate] * 1000.0, @ "wav"]]; Settings for file names

Setup the recorder to use this file and record to it.

Avaudiorecorder *recorder = [[ avaudiorecorder alloc] initwithurl: recordedtmpfile settings : Recordsettingerror: &error];

[Recorder Preparetorecord];

[Recorder record];

The following code should be the current. m file load time set

Avaudiosession * audiosession = [avaudiosession sharedinstance];

[Audiosession setcategory: Avaudiosessioncategoryplayandrecord error: &error];//set audio category, This means that when the app starts, the background other audio is stopped

[Audiosession setActive:YES Error: &error];//Set current app audio activity

About recording under iOS

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.