                 let videoLayer = AVCaptureVideoPreviewLayer(session: session)
                 videoLayer?.frame = self.previewViewContainer.bounds
                 videoLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
-                
+
+                for device in AVCaptureDevice.devices(withMediaType: AVMediaTypeAudio) {
+                    let device = device as? AVCaptureDevice
+                    let audioInput = try! AVCaptureDeviceInput(device: device)
+                    session.addInput(audioInput)
+                }
+
+                if session.canSetSessionPreset(AVCaptureSessionPreset640x480) {
+                    session.sessionPreset = AVCaptureSessionPreset640x480
+                }
+
                 self.previewViewContainer.layer.addSublayer(videoLayer!)
                 
                 session.startRunning()

                        
                    }
                }
                
            }
            
            session?.commitConfiguration()

                session.addInput(videoInput)
                
                videoOutput = AVCaptureMovieFileOutput()
                let totalSeconds = 10.0 //Total Seconds of capture time
                let timeScale: Int32 = 30 //FPS
                
                let maxDuration = CMTimeMakeWithSeconds(totalSeconds, timeScale)
