mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-04-27 15:07:43 +00:00
Fixed issue with audio going over bluetooth
This commit is contained in:
parent
6b8d19620c
commit
c98cf8256d
8 changed files with 106 additions and 73 deletions
|
|
@ -175,7 +175,7 @@
|
||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
attributes = {
|
attributes = {
|
||||||
LastSwiftUpdateCheck = 0810;
|
LastSwiftUpdateCheck = 0810;
|
||||||
LastUpgradeCheck = 0820;
|
LastUpgradeCheck = 0900;
|
||||||
ORGANIZATIONNAME = Cappsule;
|
ORGANIZATIONNAME = Cappsule;
|
||||||
TargetAttributes = {
|
TargetAttributes = {
|
||||||
05D2A9B31E80BE9700B479E9 = {
|
05D2A9B31E80BE9700B479E9 = {
|
||||||
|
|
@ -185,6 +185,7 @@
|
||||||
1675A9711E00A68300B80903 = {
|
1675A9711E00A68300B80903 = {
|
||||||
CreatedOnToolsVersion = 8.1;
|
CreatedOnToolsVersion = 8.1;
|
||||||
DevelopmentTeam = G8E5P2X66G;
|
DevelopmentTeam = G8E5P2X66G;
|
||||||
|
LastSwiftMigration = 0900;
|
||||||
ProvisioningStyle = Automatic;
|
ProvisioningStyle = Automatic;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -333,7 +334,9 @@
|
||||||
CLANG_CXX_LIBRARY = "libc++";
|
CLANG_CXX_LIBRARY = "libc++";
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
|
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_COMMA = YES;
|
||||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||||
|
|
@ -341,7 +344,11 @@
|
||||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||||
CLANG_WARN_INT_CONVERSION = YES;
|
CLANG_WARN_INT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
|
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||||
|
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||||
CLANG_WARN_SUSPICIOUS_MOVES = YES;
|
CLANG_WARN_SUSPICIOUS_MOVES = YES;
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||||
|
|
@ -383,7 +390,9 @@
|
||||||
CLANG_CXX_LIBRARY = "libc++";
|
CLANG_CXX_LIBRARY = "libc++";
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
|
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_COMMA = YES;
|
||||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||||
|
|
@ -391,7 +400,11 @@
|
||||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||||
CLANG_WARN_INT_CONVERSION = YES;
|
CLANG_WARN_INT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
|
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||||
|
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||||
CLANG_WARN_SUSPICIOUS_MOVES = YES;
|
CLANG_WARN_SUSPICIOUS_MOVES = YES;
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||||
|
|
@ -427,7 +440,8 @@
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.Walzy.DemoSwiftyCam1;
|
PRODUCT_BUNDLE_IDENTIFIER = com.Walzy.DemoSwiftyCam1;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_VERSION = 3.0;
|
SWIFT_SWIFT3_OBJC_INFERENCE = On;
|
||||||
|
SWIFT_VERSION = 4.0;
|
||||||
TARGETED_DEVICE_FAMILY = "1,2";
|
TARGETED_DEVICE_FAMILY = "1,2";
|
||||||
};
|
};
|
||||||
name = Debug;
|
name = Debug;
|
||||||
|
|
@ -442,7 +456,8 @@
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.Walzy.DemoSwiftyCam1;
|
PRODUCT_BUNDLE_IDENTIFIER = com.Walzy.DemoSwiftyCam1;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_VERSION = 3.0;
|
SWIFT_SWIFT3_OBJC_INFERENCE = On;
|
||||||
|
SWIFT_VERSION = 4.0;
|
||||||
TARGETED_DEVICE_FAMILY = "1,2";
|
TARGETED_DEVICE_FAMILY = "1,2";
|
||||||
};
|
};
|
||||||
name = Release;
|
name = Release;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "0820"
|
LastUpgradeVersion = "0900"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
language = ""
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
<Testables>
|
<Testables>
|
||||||
</Testables>
|
</Testables>
|
||||||
|
|
@ -36,6 +37,7 @@
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
language = ""
|
||||||
launchStyle = "0"
|
launchStyle = "0"
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "0820"
|
LastUpgradeVersion = "0900"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
language = ""
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
<Testables>
|
<Testables>
|
||||||
</Testables>
|
</Testables>
|
||||||
|
|
@ -45,6 +46,7 @@
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
language = ""
|
||||||
launchStyle = "0"
|
launchStyle = "0"
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>NSPhotoLibraryUsageDescription</key>
|
||||||
|
<string>To save videos</string>
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
<string>en</string>
|
<string>en</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ class PhotoViewController: UIViewController {
|
||||||
view.addSubview(cancelButton)
|
view.addSubview(cancelButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cancel() {
|
@objc func cancel() {
|
||||||
dismiss(animated: true, completion: nil)
|
dismiss(animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,20 @@ class VideoViewController: UIViewController {
|
||||||
cancelButton.setImage(#imageLiteral(resourceName: "cancel"), for: UIControlState())
|
cancelButton.setImage(#imageLiteral(resourceName: "cancel"), for: UIControlState())
|
||||||
cancelButton.addTarget(self, action: #selector(cancel), for: .touchUpInside)
|
cancelButton.addTarget(self, action: #selector(cancel), for: .touchUpInside)
|
||||||
view.addSubview(cancelButton)
|
view.addSubview(cancelButton)
|
||||||
|
|
||||||
|
|
||||||
|
// Allow background audio to continue to play
|
||||||
|
do {
|
||||||
|
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)
|
||||||
|
} catch let error as NSError {
|
||||||
|
print(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
try AVAudioSession.sharedInstance().setActive(true)
|
||||||
|
} catch let error as NSError {
|
||||||
|
print(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidAppear(_ animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
|
|
@ -65,7 +79,7 @@ class VideoViewController: UIViewController {
|
||||||
player?.play()
|
player?.play()
|
||||||
}
|
}
|
||||||
|
|
||||||
func cancel() {
|
@objc func cancel() {
|
||||||
dismiss(animated: true, completion: nil)
|
dismiss(animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,11 +55,11 @@ class PreviewView: UIView {
|
||||||
let previewlayer = layer as! AVCaptureVideoPreviewLayer
|
let previewlayer = layer as! AVCaptureVideoPreviewLayer
|
||||||
switch gravity {
|
switch gravity {
|
||||||
case .resize:
|
case .resize:
|
||||||
previewlayer.videoGravity = AVLayerVideoGravityResize
|
previewlayer.videoGravity = AVLayerVideoGravity.resize
|
||||||
case .resizeAspect:
|
case .resizeAspect:
|
||||||
previewlayer.videoGravity = AVLayerVideoGravityResizeAspect
|
previewlayer.videoGravity = AVLayerVideoGravity.resizeAspect
|
||||||
case .resizeAspectFill:
|
case .resizeAspectFill:
|
||||||
previewlayer.videoGravity = AVLayerVideoGravityResizeAspectFill
|
previewlayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
|
||||||
}
|
}
|
||||||
return previewlayer
|
return previewlayer
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -275,7 +275,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
// Test authorization status for Camera and Micophone
|
// Test authorization status for Camera and Micophone
|
||||||
|
|
||||||
switch AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) {
|
switch AVCaptureDevice.authorizationStatus(for: AVMediaType.video) {
|
||||||
case .authorized:
|
case .authorized:
|
||||||
|
|
||||||
// already authorized
|
// already authorized
|
||||||
|
|
@ -284,7 +284,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
// not yet determined
|
// not yet determined
|
||||||
sessionQueue.suspend()
|
sessionQueue.suspend()
|
||||||
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { [unowned self] granted in
|
AVCaptureDevice.requestAccess(for: AVMediaType.video, completionHandler: { [unowned self] granted in
|
||||||
if !granted {
|
if !granted {
|
||||||
self.setupResult = .notAuthorized
|
self.setupResult = .notAuthorized
|
||||||
}
|
}
|
||||||
|
|
@ -511,7 +511,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the orientation on the movie file output video connection before starting recording.
|
// Update the orientation on the movie file output video connection before starting recording.
|
||||||
let movieFileOutputConnection = self.movieFileOutput?.connection(withMediaType: AVMediaTypeVideo)
|
let movieFileOutputConnection = self.movieFileOutput?.connection(with: AVMediaType.video)
|
||||||
|
|
||||||
|
|
||||||
//flip video output if front facing camera is selected
|
//flip video output if front facing camera is selected
|
||||||
|
|
@ -524,7 +524,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
// Start recording to a temporary file.
|
// Start recording to a temporary file.
|
||||||
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(to: URL(fileURLWithPath: outputFilePath), recordingDelegate: self)
|
||||||
self.isVideoRecording = true
|
self.isVideoRecording = true
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.cameraDelegate?.swiftyCam(self, didBeginRecordingVideo: self.currentCamera)
|
self.cameraDelegate?.swiftyCam(self, didBeginRecordingVideo: self.currentCamera)
|
||||||
|
|
@ -599,7 +599,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
// remove and re-add inputs and outputs
|
// remove and re-add inputs and outputs
|
||||||
|
|
||||||
for input in self.session.inputs {
|
for input in self.session.inputs {
|
||||||
self.session.removeInput(input as! AVCaptureInput)
|
self.session.removeInput(input )
|
||||||
}
|
}
|
||||||
|
|
||||||
self.addInputs()
|
self.addInputs()
|
||||||
|
|
@ -656,12 +656,12 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
fileprivate func configureVideoPreset() {
|
fileprivate func configureVideoPreset() {
|
||||||
if currentCamera == .front {
|
if currentCamera == .front {
|
||||||
session.sessionPreset = videoInputPresetFromVideoQuality(quality: .high)
|
session.sessionPreset = AVCaptureSession.Preset(rawValue: videoInputPresetFromVideoQuality(quality: .high))
|
||||||
} else {
|
} else {
|
||||||
if session.canSetSessionPreset(videoInputPresetFromVideoQuality(quality: videoQuality)) {
|
if session.canSetSessionPreset(AVCaptureSession.Preset(rawValue: videoInputPresetFromVideoQuality(quality: videoQuality))) {
|
||||||
session.sessionPreset = videoInputPresetFromVideoQuality(quality: videoQuality)
|
session.sessionPreset = AVCaptureSession.Preset(rawValue: videoInputPresetFromVideoQuality(quality: videoQuality))
|
||||||
} else {
|
} else {
|
||||||
session.sessionPreset = videoInputPresetFromVideoQuality(quality: .high)
|
session.sessionPreset = AVCaptureSession.Preset(rawValue: videoInputPresetFromVideoQuality(quality: .high))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -671,9 +671,9 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
fileprivate func addVideoInput() {
|
fileprivate func addVideoInput() {
|
||||||
switch currentCamera {
|
switch currentCamera {
|
||||||
case .front:
|
case .front:
|
||||||
videoDevice = SwiftyCamViewController.deviceWithMediaType(AVMediaTypeVideo, preferringPosition: .front)
|
videoDevice = SwiftyCamViewController.deviceWithMediaType(AVMediaType.video.rawValue, preferringPosition: .front)
|
||||||
case .rear:
|
case .rear:
|
||||||
videoDevice = SwiftyCamViewController.deviceWithMediaType(AVMediaTypeVideo, preferringPosition: .back)
|
videoDevice = SwiftyCamViewController.deviceWithMediaType(AVMediaType.video.rawValue, preferringPosition: .back)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let device = videoDevice {
|
if let device = videoDevice {
|
||||||
|
|
@ -705,14 +705,14 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let videoDeviceInput = try AVCaptureDeviceInput(device: videoDevice)
|
let videoDeviceInput = try AVCaptureDeviceInput(device: videoDevice!)
|
||||||
|
|
||||||
if session.canAddInput(videoDeviceInput) {
|
if session.canAddInput(videoDeviceInput) {
|
||||||
session.addInput(videoDeviceInput)
|
session.addInput(videoDeviceInput)
|
||||||
self.videoDeviceInput = videoDeviceInput
|
self.videoDeviceInput = videoDeviceInput
|
||||||
} else {
|
} else {
|
||||||
print("[SwiftyCam]: Could not add video device input to the session")
|
print("[SwiftyCam]: Could not add video device input to the session")
|
||||||
print(session.canSetSessionPreset(videoInputPresetFromVideoQuality(quality: videoQuality)))
|
print(session.canSetSessionPreset(AVCaptureSession.Preset(rawValue: videoInputPresetFromVideoQuality(quality: videoQuality))))
|
||||||
setupResult = .configurationFailed
|
setupResult = .configurationFailed
|
||||||
session.commitConfiguration()
|
session.commitConfiguration()
|
||||||
return
|
return
|
||||||
|
|
@ -731,8 +731,8 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
let audioDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeAudio)
|
let audioDevice = AVCaptureDevice.default(for: AVMediaType.audio)
|
||||||
let audioDeviceInput = try AVCaptureDeviceInput(device: audioDevice)
|
let audioDeviceInput = try AVCaptureDeviceInput(device: audioDevice!)
|
||||||
|
|
||||||
if session.canAddInput(audioDeviceInput) {
|
if session.canAddInput(audioDeviceInput) {
|
||||||
session.addInput(audioDeviceInput)
|
session.addInput(audioDeviceInput)
|
||||||
|
|
@ -753,7 +753,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
if self.session.canAddOutput(movieFileOutput) {
|
if self.session.canAddOutput(movieFileOutput) {
|
||||||
self.session.addOutput(movieFileOutput)
|
self.session.addOutput(movieFileOutput)
|
||||||
if let connection = movieFileOutput.connection(withMediaType: AVMediaTypeVideo) {
|
if let connection = movieFileOutput.connection(with: AVMediaType.video) {
|
||||||
if connection.isVideoStabilizationSupported {
|
if connection.isVideoStabilizationSupported {
|
||||||
connection.preferredVideoStabilizationMode = .auto
|
connection.preferredVideoStabilizationMode = .auto
|
||||||
}
|
}
|
||||||
|
|
@ -807,7 +807,7 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func getVideoOrientation() -> AVCaptureVideoOrientation {
|
fileprivate func getVideoOrientation() -> AVCaptureVideoOrientation {
|
||||||
guard shouldUseDeviceOrientation, let deviceOrientation = self.deviceOrientation else { return previewLayer!.videoPreviewLayer.connection.videoOrientation }
|
guard shouldUseDeviceOrientation, let deviceOrientation = self.deviceOrientation else { return previewLayer!.videoPreviewLayer.connection!.videoOrientation }
|
||||||
|
|
||||||
switch deviceOrientation {
|
switch deviceOrientation {
|
||||||
case .landscapeLeft:
|
case .landscapeLeft:
|
||||||
|
|
@ -863,11 +863,11 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if let videoConnection = photoFileOutput?.connection(withMediaType: AVMediaTypeVideo) {
|
if let videoConnection = photoFileOutput?.connection(with: AVMediaType.video) {
|
||||||
|
|
||||||
photoFileOutput?.captureStillImageAsynchronously(from: videoConnection, completionHandler: {(sampleBuffer, error) in
|
photoFileOutput?.captureStillImageAsynchronously(from: videoConnection, completionHandler: {(sampleBuffer, error) in
|
||||||
if (sampleBuffer != nil) {
|
if (sampleBuffer != nil) {
|
||||||
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
|
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer!)
|
||||||
let image = self.processPhoto(imageData!)
|
let image = self.processPhoto(imageData!)
|
||||||
|
|
||||||
// Call delegate and return new image
|
// Call delegate and return new image
|
||||||
|
|
@ -916,38 +916,35 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
fileprivate func videoInputPresetFromVideoQuality(quality: VideoQuality) -> String {
|
fileprivate func videoInputPresetFromVideoQuality(quality: VideoQuality) -> String {
|
||||||
switch quality {
|
switch quality {
|
||||||
case .high: return AVCaptureSessionPresetHigh
|
case .high: return AVCaptureSession.Preset.high.rawValue
|
||||||
case .medium: return AVCaptureSessionPresetMedium
|
case .medium: return AVCaptureSession.Preset.medium.rawValue
|
||||||
case .low: return AVCaptureSessionPresetLow
|
case .low: return AVCaptureSession.Preset.low.rawValue
|
||||||
case .resolution352x288: return AVCaptureSessionPreset352x288
|
case .resolution352x288: return AVCaptureSession.Preset.cif352x288.rawValue
|
||||||
case .resolution640x480: return AVCaptureSessionPreset640x480
|
case .resolution640x480: return AVCaptureSession.Preset.vga640x480.rawValue
|
||||||
case .resolution1280x720: return AVCaptureSessionPreset1280x720
|
case .resolution1280x720: return AVCaptureSession.Preset.hd1280x720.rawValue
|
||||||
case .resolution1920x1080: return AVCaptureSessionPreset1920x1080
|
case .resolution1920x1080: return AVCaptureSession.Preset.hd1920x1080.rawValue
|
||||||
case .iframe960x540: return AVCaptureSessionPresetiFrame960x540
|
case .iframe960x540: return AVCaptureSession.Preset.iFrame960x540.rawValue
|
||||||
case .iframe1280x720: return AVCaptureSessionPresetiFrame1280x720
|
case .iframe1280x720: return AVCaptureSession.Preset.iFrame1280x720.rawValue
|
||||||
case .resolution3840x2160:
|
case .resolution3840x2160:
|
||||||
if #available(iOS 9.0, *) {
|
if #available(iOS 9.0, *) {
|
||||||
return AVCaptureSessionPreset3840x2160
|
return AVCaptureSession.Preset.hd4K3840x2160.rawValue
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print("[SwiftyCam]: Resolution 3840x2160 not supported")
|
print("[SwiftyCam]: Resolution 3840x2160 not supported")
|
||||||
return AVCaptureSessionPresetHigh
|
return AVCaptureSession.Preset.high.rawValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get Devices
|
/// Get Devices
|
||||||
|
|
||||||
fileprivate class func deviceWithMediaType(_ mediaType: String, preferringPosition position: AVCaptureDevicePosition) -> AVCaptureDevice? {
|
fileprivate class func deviceWithMediaType(_ mediaType: String, preferringPosition position: AVCaptureDevice.Position) -> AVCaptureDevice? {
|
||||||
if let devices = AVCaptureDevice.devices(withMediaType: mediaType) as? [AVCaptureDevice] {
|
return AVCaptureDevice.devices(for: AVMediaType(rawValue: mediaType)).first
|
||||||
return devices.filter({ $0.position == position }).first
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enable or disable flash for photo
|
/// Enable or disable flash for photo
|
||||||
|
|
||||||
fileprivate func changeFlashSettings(device: AVCaptureDevice, mode: AVCaptureFlashMode) {
|
fileprivate func changeFlashSettings(device: AVCaptureDevice, mode: AVCaptureDevice.FlashMode) {
|
||||||
do {
|
do {
|
||||||
try device.lockForConfiguration()
|
try device.lockForConfiguration()
|
||||||
device.flashMode = mode
|
device.flashMode = mode
|
||||||
|
|
@ -981,17 +978,17 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let device = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
|
let device = AVCaptureDevice.default(for: AVMediaType.video)
|
||||||
// Check if device has a flash
|
// Check if device has a flash
|
||||||
if (device?.hasTorch)! {
|
if (device?.hasTorch)! {
|
||||||
do {
|
do {
|
||||||
try device?.lockForConfiguration()
|
try device?.lockForConfiguration()
|
||||||
if (device?.torchMode == AVCaptureTorchMode.on) {
|
if (device?.torchMode == AVCaptureDevice.TorchMode.on) {
|
||||||
device?.torchMode = AVCaptureTorchMode.off
|
device?.torchMode = AVCaptureDevice.TorchMode.off
|
||||||
self.isCameraTorchOn = false
|
self.isCameraTorchOn = false
|
||||||
} else {
|
} else {
|
||||||
do {
|
do {
|
||||||
try device?.setTorchModeOnWithLevel(1.0)
|
try device?.setTorchModeOn(level: 1.0)
|
||||||
self.isCameraTorchOn = true
|
self.isCameraTorchOn = true
|
||||||
} catch {
|
} catch {
|
||||||
print("[SwiftyCam]: \(error)")
|
print("[SwiftyCam]: \(error)")
|
||||||
|
|
@ -1090,7 +1087,7 @@ extension SwiftyCamViewController : AVCaptureFileOutputRecordingDelegate {
|
||||||
|
|
||||||
/// Process newly captured video and write it to temporary directory
|
/// Process newly captured video and write it to temporary directory
|
||||||
|
|
||||||
public func capture(_ captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAt outputFileURL: URL!, fromConnections connections: [Any]!, error: Error!) {
|
public func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) {
|
||||||
if let currentBackgroundRecordingID = backgroundRecordingID {
|
if let currentBackgroundRecordingID = backgroundRecordingID {
|
||||||
backgroundRecordingID = UIBackgroundTaskInvalid
|
backgroundRecordingID = UIBackgroundTaskInvalid
|
||||||
|
|
||||||
|
|
@ -1098,10 +1095,11 @@ extension SwiftyCamViewController : AVCaptureFileOutputRecordingDelegate {
|
||||||
UIApplication.shared.endBackgroundTask(currentBackgroundRecordingID)
|
UIApplication.shared.endBackgroundTask(currentBackgroundRecordingID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if error != nil {
|
|
||||||
print("[SwiftyCam]: Movie file finishing error: \(error)")
|
if let currentError = error {
|
||||||
|
print("[SwiftyCam]: Movie file finishing error: \(currentError)")
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.cameraDelegate?.swiftyCam(self, didFailToRecordVideo: error)
|
self.cameraDelegate?.swiftyCam(self, didFailToRecordVideo: currentError)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//Call delegate function with the URL of the outputfile
|
//Call delegate function with the URL of the outputfile
|
||||||
|
|
@ -1124,7 +1122,7 @@ extension SwiftyCamViewController {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
let captureDevice = AVCaptureDevice.devices().first as? AVCaptureDevice
|
let captureDevice = AVCaptureDevice.devices().first
|
||||||
try captureDevice?.lockForConfiguration()
|
try captureDevice?.lockForConfiguration()
|
||||||
|
|
||||||
zoomScale = min(maxZoomScale, max(1.0, min(beginZoomScale * pinch.scale, captureDevice!.activeFormat.videoMaxZoomFactor)))
|
zoomScale = min(maxZoomScale, max(1.0, min(beginZoomScale * pinch.scale, captureDevice!.activeFormat.videoMaxZoomFactor)))
|
||||||
|
|
@ -1166,7 +1164,7 @@ extension SwiftyCamViewController {
|
||||||
device.focusMode = .autoFocus
|
device.focusMode = .autoFocus
|
||||||
}
|
}
|
||||||
device.exposurePointOfInterest = focusPoint
|
device.exposurePointOfInterest = focusPoint
|
||||||
device.exposureMode = AVCaptureExposureMode.continuousAutoExposure
|
device.exposureMode = AVCaptureDevice.ExposureMode.continuousAutoExposure
|
||||||
device.unlockForConfiguration()
|
device.unlockForConfiguration()
|
||||||
//Call delegate function and pass in the location of the touch
|
//Call delegate function and pass in the location of the touch
|
||||||
|
|
||||||
|
|
@ -1199,7 +1197,7 @@ extension SwiftyCamViewController {
|
||||||
let translationDifference = currentTranslation - previousPanTranslation
|
let translationDifference = currentTranslation - previousPanTranslation
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let captureDevice = AVCaptureDevice.devices().first as? AVCaptureDevice
|
let captureDevice = AVCaptureDevice.devices().first
|
||||||
try captureDevice?.lockForConfiguration()
|
try captureDevice?.lockForConfiguration()
|
||||||
|
|
||||||
let currentZoom = captureDevice?.videoZoomFactor ?? 0.0
|
let currentZoom = captureDevice?.videoZoomFactor ?? 0.0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue