Skip to content

Commit

Permalink
Output allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfej94 committed Jan 4, 2022
1 parent bed4308 commit caa6b27
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion PhotographyKit.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |spec|

spec.name = "PhotographyKit"
spec.version = "0.24"
spec.version = "0.25"
spec.license = "MIT"
spec.summary = "A swift library for quickly integrating a built in camera session into your app."
spec.homepage = "https://github.com/appoly/PhotographyKit"
Expand Down
Binary file modified Sources/.DS_Store
Binary file not shown.
30 changes: 24 additions & 6 deletions Sources/PhotographyKit/PhotographyKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum PhotographyKitError: Error {
case failedToConnectToDeviceTorch
case failedToConnectToDeviceMicrophone
case failedToCreateVideoFile
case failedToAddOutput
}


Expand All @@ -44,6 +45,8 @@ extension PhotographyKitError: LocalizedError {
return "Failed to connect to device microphone"
case .failedToCreateVideoFile:
return "Failed to create video file for recording"
case .failedToAddOutput:
return "Failed to add output"
}
}
}
Expand All @@ -67,7 +70,7 @@ public class PhotographyKit: NSObject {

//User defined photo settings
private let zoomSensitivity: CGFloat = 0.03
private let delegate: PhotographyKitDelegate
private let delegate: PhotographyKitDelegate?
private let allowsVideo: Bool

//Capture session
Expand All @@ -87,6 +90,11 @@ public class PhotographyKit: NSObject {

// MARK: - Actions

/// Stop Capture session
public func stop() {
captureSession?.stopRunning()
}

/// Tries to resets the capture session, starting the preview again.
public func resetCamera() throws {
photo = nil
Expand Down Expand Up @@ -116,6 +124,16 @@ public class PhotographyKit: NSObject {
}


///Adds output to capture session
public func addOutput(output: AVCaptureOutput) throws {
if(captureSession?.canAddOutput(output) ?? false) {
captureSession?.addOutput(output)
} else {
throw PhotographyKitError.failedToAddOutput
}
}


public func endVideoRecording() {
guard allowsVideo else { return }
movieFileOutput.stopRecording()
Expand Down Expand Up @@ -226,7 +244,7 @@ public class PhotographyKit: NSObject {

// MARK: - Initializers

public init?(view: UIView, delegate: PhotographyKitDelegate, allowsVideo: Bool) throws {
public init?(view: UIView, delegate: PhotographyKitDelegate?, allowsVideo: Bool) throws {
self.allowsVideo = allowsVideo
self.delegate = delegate
super.init()
Expand Down Expand Up @@ -399,7 +417,7 @@ extension PhotographyKit: AVCapturePhotoCaptureDelegate {
guard let image = getImageFrom(photo) else { return }

let photo = PhotographyKitPhoto(image: image)
delegate.didCaptureImage(image: photo)
delegate?.didCaptureImage(image: photo)
}

}
Expand All @@ -409,16 +427,16 @@ extension PhotographyKit: AVCapturePhotoCaptureDelegate {
extension PhotographyKit: AVCaptureFileOutputRecordingDelegate {

public func fileOutput(_ output: AVCaptureFileOutput, didStartRecordingTo fileURL: URL, from connections: [AVCaptureConnection]) {
delegate.didStartRecordingVideo()
delegate?.didStartRecordingVideo()
}


public func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) {
guard error == nil else {
delegate.didFailRecordingVideo(error: error!)
delegate?.didFailRecordingVideo(error: error!)
return
}
delegate.didFinishRecordingVideo(url: outputFileURL)
delegate?.didFinishRecordingVideo(url: outputFileURL)
}

}

0 comments on commit caa6b27

Please sign in to comment.