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