From 5fcc21edf9b313480e118586631b71b380b3a6e5 Mon Sep 17 00:00:00 2001 From: Andrew Walz Date: Mon, 29 May 2017 21:21:39 -0600 Subject: [PATCH] Added support for no audio video recording --- DemoSwiftyCam/DemoSwiftyCam/ViewController.swift | 1 + Source/SwiftyCamViewController.swift | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift b/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift index 4fdf418..ff69e22 100644 --- a/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift +++ b/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift @@ -28,6 +28,7 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate { maximumVideoDuration = 10.0 shouldUseDeviceOrientation = true allowAutoRotate = false + audioEnabled = true addButtons() } diff --git a/Source/SwiftyCamViewController.swift b/Source/SwiftyCamViewController.swift index 6a47639..a8588ee 100644 --- a/Source/SwiftyCamViewController.swift +++ b/Source/SwiftyCamViewController.swift @@ -153,6 +153,10 @@ open class SwiftyCamViewController: UIViewController { /// Specifies the [videoGravity](https://developer.apple.com/reference/avfoundation/avcapturevideopreviewlayer/1386708-videogravity) for the preview layer. public var videoGravity : SwiftyCamVideoGravity = .resizeAspect + + /// Sets whether or not video recordings will record audio + /// Setting to true will prompt user for access to microphone on View Controller launch. + public var audioEnabled = true // MARK: Public Get-only Variable Declarations @@ -694,6 +698,9 @@ open class SwiftyCamViewController: UIViewController { /// Add Audio Inputs fileprivate func addAudioInput() { + guard audioEnabled == true else { + return + } do { let audioDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeAudio) let audioDeviceInput = try AVCaptureDeviceInput(device: audioDevice) @@ -968,6 +975,10 @@ open class SwiftyCamViewController: UIViewController { guard allowBackgroundAudio == true else { return } + + guard audioEnabled == true else { + return + } do{ try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord,