![]() ![]() For usage of other methods, you can refer to the official documentation of AUAudioPlayerDelegate protocol.Īdd the following code in ViewController.This method receives as parameter a CMTime, which will be used as a starting point of each chunk of video.ġ- First, we have to check if we already have a record stored and delete it to get space for the next one. To demonstrate how it works, we’ll implement the “audioPlayerDidFinishPlaying:” method to display an alert prompt after the completion of audio playback. All methods in AVAudioplayerDelegate protocol are optional, however. The delegate allows you to handle interruptions, audio decoding errors and update the user interface when an audio has finished playing. The delegate of an AVAudioPlayer object must adopt the AVAudioPlayerDelegate protocol. Implementing the AVAudioPlayerDelegate Protocol Call play: method to play the sound file.Designate an audio player delegate object, which handles interruptions as well as the playback-completed event.In the case, it’s the audio file of the recording (i.e. Initialize the audio play and Assign a sound file to it.Normally, there are a few things to configure an audio player: The audio recording will only be stopped when user taps the “Stop” button.Įdit the “recordPauseTapped:” method with the following code: If user taps the “Pause” button, the app will pause the audio recording till the “Record” is tapped again. 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”. 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 |