iOS about recording, playback implementation summary

Source: Internet
Author: User

Audio recording (standard process 5,9 update)

Prepare: Import avfoundation frame and header file


1 setting session type, allowing playback and recording
Avaudiosession *audiosession = [Avaudiosession sharedinstance];

[Audiosession Setcategory:avaudiosessioncategoryplayandrecord Error:nil];

2 Activating session Categories
[Audiosession Setactive:yes Error:nil];

3 Package dictionary parameters, audio format int, sample rate float, channel number int, depth int
is set by KVC (SetValue Forkey)
Nsdictionary *setting=[nsdictionary Dictionary];

[Setting Setvalue:[nsnumber NUMBERWITHINT:KAUDIOFORMATAPPLEIMA4] forkey:avformatidkey];

4 Package sandbox path to save audio

5 instantiation of the recording object, parameters: Save URL, parameter dictionary, error,
Note that simulator debugging can only be saved to the sandbox,
Avaudiorecorder *recorder = [[Avaudiorecorder alloc]initwithurl: (Nsurl *) settings: (Nsdictionary *) error:&error];

6 pre-load ready for recording
[Recorder Preparerecorder];

7 Processing button Tap Listen recording
Monitor button touchdown: recording open [recorder recorder];
Monitor button Touchupinset: The finger is lifted when the button is clicked
and Touchupoutset: The finger is lifted in the other place after the button is clicked
Stop recording [recorder stop];


Summary of the recording implementation:
1 instantiate a single Session object, set the conversation category to recording and playback mode, open the session
2 Instantiate the recording object, parameters are stored sandbox path, audio dictionary parameters (audio format, sample rate, depth, etc.)
3 Package Sandbox path
4 instantiation of the Audio object path dictionary parameter error
5 Pre-load open
6 Tap status of the Monitor button, press the recording, lift stop
7 Listen click to instantiate audio playback object, fill in URL, play open

Audio playback
Apple recommended Audio type: AAC,IMA4,CAF (Coreaudioformat)

1 avfoundation
(Play only local audio, not network audio)
_player=[avaudioplayer Alloc]initwithcontentsofurl:url Error:nil];

[_player play];

Summary: Play local audio three steps
"1" Package Audio URL Path
"2" class method initialize audio object, parameter URL error handling
"3" Object Open
There are many properties in the object set cycle times, play control (Play/stop), and preload methods Preparetoplay

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.