title: Swift IOS Record Video and Audio with AVFoundation
body: <p>I was able to successfully grab the recorded video by following this question
  <a href="https://stackoverflow.com/questions/24419643/what-am-i-doing-wrong-while-record-video-avfoundation-with-swift">here</a></p>
  <p>Basically</p>
  <ol>
  <li>Inherit from <code>AVCaptureFileOutputRecordingDelegate</code> prototype</li>
  <li>Loop through available devices</li>
  <li>Creating a session with the camera</li>
  <li>Start Recording</li>
  <li>Stop Recording</li>
  <li>Get the Record video by implementing above prototype's method</li>
  </ol>
  <p>But the file doesn't comes with the audio.</p>
  <p>According to <a href="https://stackoverflow.com/questions/8046102/recording-audio-and-video-using-avfoundation-frame-by-frame">this</a> question, i have to record audio separately and merge the video and audio using mentioned classes</p>
  <p>But i have no idea how to implement video and audio recording at the same time.</p>
  <pre><code>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(&quot;Capture device found&quot;)
  
                  beginSession()
              }
          }
      }
  }
  </code></pre>
  <p>in this loop only available device types are .Front and .Back</p>