mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-04-27 15:07:43 +00:00
Background audio recording now works as expected
This commit is contained in:
parent
4c3a2c8f47
commit
f7b52dea9f
1 changed files with 32 additions and 5 deletions
|
|
@ -123,12 +123,16 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
public var promptToAppPrivacySettings = true
|
public var promptToAppPrivacySettings = true
|
||||||
|
|
||||||
|
/// Set whether SwiftyCam should allow background audio from other applications
|
||||||
|
|
||||||
|
public var allowBackgroundAudio = true
|
||||||
|
|
||||||
|
|
||||||
// MARK: Public Get-only Variable Declarations
|
// MARK: Public Get-only Variable Declarations
|
||||||
|
|
||||||
/// Returns true if video is currently being recorded
|
/// Returns true if video is currently being recorded
|
||||||
|
|
||||||
private(set) public var isVideRecording = false
|
private(set) public var isVideoRecording = false
|
||||||
|
|
||||||
/// Returns true if the capture session is currently running
|
/// Returns true if the capture session is currently running
|
||||||
|
|
||||||
|
|
@ -208,7 +212,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
override open func viewDidLoad() {
|
override open func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
previewLayer = PreviewView(frame: self.view.frame)
|
previewLayer = PreviewView(frame: self.view.frame)
|
||||||
|
|
||||||
// Add Pinch Gesture Recognizer for pinch to zoom
|
// Add Pinch Gesture Recognizer for pinch to zoom
|
||||||
|
|
||||||
addGestureRecognizersTo(view: previewLayer)
|
addGestureRecognizersTo(view: previewLayer)
|
||||||
|
|
@ -251,6 +255,10 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
override open func viewDidAppear(_ animated: Bool) {
|
override open func viewDidAppear(_ animated: Bool) {
|
||||||
super.viewDidAppear(animated)
|
super.viewDidAppear(animated)
|
||||||
|
|
||||||
|
// Set background audio preference
|
||||||
|
|
||||||
|
setBackgroundAudioPreference()
|
||||||
|
|
||||||
sessionQueue.async {
|
sessionQueue.async {
|
||||||
switch self.setupResult {
|
switch self.setupResult {
|
||||||
case .success:
|
case .success:
|
||||||
|
|
@ -386,7 +394,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
let outputFileName = UUID().uuidString
|
let outputFileName = UUID().uuidString
|
||||||
let outputFilePath = (NSTemporaryDirectory() as NSString).appendingPathComponent((outputFileName as NSString).appendingPathExtension("mov")!)
|
let outputFilePath = (NSTemporaryDirectory() as NSString).appendingPathComponent((outputFileName as NSString).appendingPathExtension("mov")!)
|
||||||
movieFileOutput.startRecording(toOutputFileURL: URL(fileURLWithPath: outputFilePath), recordingDelegate: self)
|
movieFileOutput.startRecording(toOutputFileURL: URL(fileURLWithPath: outputFilePath), recordingDelegate: self)
|
||||||
self.isVideRecording = true
|
self.isVideoRecording = true
|
||||||
self.cameraDelegate?.SwiftyCamDidBeginRecordingVideo()
|
self.cameraDelegate?.SwiftyCamDidBeginRecordingVideo()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -407,7 +415,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
public func endVideoRecording() {
|
public func endVideoRecording() {
|
||||||
if self.movieFileOutput?.isRecording == true {
|
if self.movieFileOutput?.isRecording == true {
|
||||||
self.isVideRecording = false
|
self.isVideoRecording = false
|
||||||
movieFileOutput!.stopRecording()
|
movieFileOutput!.stopRecording()
|
||||||
disableFlash()
|
disableFlash()
|
||||||
|
|
||||||
|
|
@ -432,7 +440,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
|
|
||||||
public func switchCamera() {
|
public func switchCamera() {
|
||||||
guard isVideRecording != true else {
|
guard isVideoRecording != true else {
|
||||||
//TODO: Look into switching camera during video recording
|
//TODO: Look into switching camera during video recording
|
||||||
print("[SwiftyCam]: Switching between cameras while recording video is not supported")
|
print("[SwiftyCam]: Switching between cameras while recording video is not supported")
|
||||||
return
|
return
|
||||||
|
|
@ -858,6 +866,25 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets whether SwiftyCam should enable background audio from other applications or sources
|
||||||
|
|
||||||
|
fileprivate func setBackgroundAudioPreference() {
|
||||||
|
guard allowBackgroundAudio == true else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
do{
|
||||||
|
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord,
|
||||||
|
with: [.duckOthers, .defaultToSpeaker])
|
||||||
|
|
||||||
|
session.automaticallyConfiguresApplicationAudioSession = false
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
print("[SwiftyCam]: Failed to set background audio preference")
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SwiftyCamViewController : SwiftyCamButtonDelegate {
|
extension SwiftyCamViewController : SwiftyCamButtonDelegate {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue