![]() ![]()
When user taps the “Record” button, the app will start recording and the button text will be changed to “Pause”. Before we dive into the code, let me explain how the “Record” button works. Let’s move on to implement the action method of Record button. Note: For other settings keys, you can refer to AV Foundation Audio Settings Constants. Lastly, we initiate the audio recorder by calling “prepareToRecord:” method. In line 21-25, we use the options keys to configure the audio data format, sample rate and number of channels. The AVAudioRecorder uses a dictionary-based settings for its configuration. We will not go into the details of audio session but you can check out the official document for further details. Here, we tell iOS that the app uses “AVAudioSessionCategoryPlayAndRecord” category which enables both audio input and output. You can grab such session by calling and configure it. Upon launch, your app automatically gets an audio session. iOS handles audio behaviour of an app by using audio sessions. In the above code, we first define the sound file URL for saving the recording. In real app, don’t forget to include proper error handling. Note: For demo purpose, we skip the error handling. Recorder = initWithURL:outputFileURL settings:recordSetting error:NULL] ![]() NSMutableDictionary *recordSetting = init] NSArray *pathComponents = [NSArray arrayWithObjects: Disable Stop/Play button when application launches ![]() The buttons are also linked up with the code. I’ve created a simple UI for you that it only contains three buttons including “Record”, “Stop” and “Play”. Avrecorder save file but keep recording code#To free you from setting up the user interface and code skeleton, you can download the project template from here.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |