I was able to successfully grab the recorded video by following this question here
Basically
- Inherit from
AVCaptureFileOutputRecordingDelegate
prototype - Loop through available devices
- Creating a session with the camera
- Start Recording
- Stop Recording
- Get the Record video by implementing above prototype's method
But the file doesn't comes with the audio.
According to this question, i have to record audio separately and merge the video and audio using mentioned classes
But i have no idea how to implement video and audio recording at the same time.
for device in devices {
// Make sure this particular device supports video
if (device.hasMediaType(AVMediaTypeVideo)) {
// Finally check the position and confirm we've got the back camera
if(device.position == AVCaptureDevicePosition.Back) {
captureDevice = device as? AVCaptureDevice
if captureDevice != nil {
print("Capture device found")
beginSession()
}
}
}
}
in this loop only available device types are .Front and .Back
I had this problem also, but when I grouped adding the video input and the sound input after, the audio worked. This is my code for adding the inputs.
Also I found you have to have video input first or else there won't be audio. I originally had them in two if statements, but I found putting them in one lets video and audio be recorded together. Hope this helps.
Found the answer, This answer goes with this code
It can simply done by
code
Loop through devices and Initialize capture devices
Inside Session
This will output the video file with audio. no need to merge audio or do anything.
This apples documentation helps
Record Video With Audio
For more details refer this link:
https://medium.com/@santhosh3386/ios-avcapturesession-record-video-with-audio-23c8f8c9a8f8
Following is the way to record video with audio using AVFoundation framework. The steps are:
1. Prepare the session:
2. Prepare available video and audio devices:
3. Prepare session inputs:
4. Prepare output:
5. Start recording:
6. Stop recording:
7. Implement the delegate:
I took idea from here: https://www.appcoda.com/avfoundation-swift-guide/
Here is the complete project https://github.com/rubaiyat6370/iOS-Tutorial/