Commit baa54bba by Daniel Dahan

development: progression commit for Capture updates

parent d7bea33c
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_camera_front_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_camera_front_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_camera_front_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_camera_rear_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_camera_rear_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_camera_rear_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_flash_auto_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_auto_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_auto_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_flash_off_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_off_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_off_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_flash_on_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_on_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_on_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_photo_camera_white_36pt.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_photo_camera_white_36pt@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_photo_camera_white_36pt@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_videocam_white_36pt.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_videocam_white_36pt@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_videocam_white_36pt@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -135,88 +135,8 @@ open class Capture: View, UIGestureRecognizerDelegate {
/// A delegation reference.
open weak var delegate: CaptureDelegate?
/// A Timer reference for when recording is enabled.
private var timer: Timer?
/// A tap gesture reference for focus events.
private var tapToFocusGesture: UITapGestureRecognizer?
/// A tap gesture reference for exposure events.
private var tapToExposeGesture: UITapGestureRecognizer?
/// A tap gesture reference for reset events.
private var tapToResetGesture: UITapGestureRecognizer?
/// A reference to the capture mode.
open var captureMode = CaptureMode.video
/// A boolean indicating whether to enable tap to focus.
@IBInspectable
open var isTapToFocusEnabled = false {
didSet {
guard isTapToFocusEnabled else {
removeTapGesture(gesture: &tapToFocusGesture)
focusView?.removeFromSuperview()
focusView = nil
return
}
isTapToResetEnabled = true
prepareFocusLayer()
prepareTapGesture(gesture: &tapToFocusGesture, numberOfTapsRequired: 1, numberOfTouchesRequired: 1, selector: #selector(handleTapToFocusGesture))
if let v = tapToExposeGesture {
tapToFocusGesture!.require(toFail: v)
}
}
}
/// A boolean indicating whether to enable tap to expose.
@IBInspectable
open var isTapToExposeEnabled = false {
didSet {
guard isTapToExposeEnabled else {
removeTapGesture(gesture: &tapToExposeGesture)
exposureView?.removeFromSuperview()
exposureView = nil
return
}
isTapToResetEnabled = true
prepareExposureLayer()
prepareTapGesture(gesture: &tapToExposeGesture, numberOfTapsRequired: 2, numberOfTouchesRequired: 1, selector: #selector(handleTapToExposeGesture))
if let v = tapToFocusGesture {
v.require(toFail: tapToExposeGesture!)
}
}
}
/// A boolean indicating whether to enable tap to reset.
@IBInspectable
open var isTapToResetEnabled = false {
didSet {
guard isTapToResetEnabled else {
removeTapGesture(gesture: &tapToResetGesture)
resetView?.removeFromSuperview()
resetView = nil
return
}
prepareResetLayer()
prepareTapGesture(gesture: &tapToResetGesture, numberOfTapsRequired: 2, numberOfTouchesRequired: 2, selector: #selector(handleTapToResetGesture))
if let v = tapToFocusGesture {
v.require(toFail: tapToResetGesture!)
}
if let v = tapToExposeGesture {
v.require(toFail: tapToResetGesture!)
}
}
}
open var mode = CaptureMode.video
/// Insets preset value for content.
open var contentEdgeInsetsPreset = EdgeInsetsPreset.none {
......@@ -229,7 +149,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
@IBInspectable
open var contentEdgeInsets = EdgeInsets.zero {
didSet {
reloadView()
layoutSubviews()
}
}
......@@ -249,53 +169,19 @@ open class Capture: View, UIGestureRecognizerDelegate {
open internal(set) var resetView: UIView?
/// A reference to the cameraButton.
open private(set) var cameraButton: IconButton! {
didSet {
if let v = cameraButton {
v.addTarget(self, action: #selector(handleCameraButton), for: .touchUpInside)
}
reloadView()
}
}
open private(set) var cameraButton: IconButton!
/// A reference to the captureButton.
open private(set) var captureButton: FabButton! {
didSet {
if let v = captureButton {
v.addTarget(self, action: #selector(handleCaptureButton), for: .touchUpInside)
}
reloadView()
}
}
open private(set) var captureButton: FabButton!
/// A reference to the videoButton.
open private(set) var videoButton: IconButton! {
didSet {
if let v = videoButton {
v.addTarget(self, action: #selector(handleVideoButton), for: .touchUpInside)
}
reloadView()
}
}
open private(set) var videoButton: IconButton!
/// A reference to the switchCameraButton.
open private(set) var switchCamerasButton: IconButton! {
didSet {
if let v = switchCamerasButton {
v.addTarget(self, action: #selector(handleSwitchCamerasButton), for: .touchUpInside)
}
}
}
open private(set) var switchCamerasButton: IconButton!
/// A reference to the flashButton.
open private(set) var flashButton: IconButton! {
didSet {
if let v = flashButton {
v.addTarget(self, action: #selector(handleFlashButton), for: .touchUpInside)
}
}
}
open private(set) var flashButton: IconButton!
/// A convenience initializer.
public convenience init() {
......@@ -304,26 +190,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
open override func layoutSubviews() {
super.layoutSubviews()
preview.frame = bounds
if let v = cameraButton {
v.y = bounds.height - contentEdgeInsets.bottom - v.bounds.height
v.x = contentEdgeInsets.left
}
if let v = captureButton {
v.y = bounds.height - contentEdgeInsets.bottom - v.bounds.height
v.x = (bounds.width - v.width) / 2
}
if let v = videoButton {
v.y = bounds.height - contentEdgeInsets.bottom - v.bounds.height
v.x = bounds.width - v.width - contentEdgeInsets.right
}
if let v = (preview.layer as! AVCaptureVideoPreviewLayer).connection {
v.videoOrientation = session.videoOrientation
}
reload()
}
/**
......@@ -336,75 +203,20 @@ open class Capture: View, UIGestureRecognizerDelegate {
open override func prepare() {
super.prepare()
backgroundColor = .black
contentEdgeInsetsPreset = .square4
prepareCaptureSession()
preparePreviewView()
preparePreview()
prepareCaptureButton()
prepareCameraButton()
prepareVideoButton()
prepareSwitchCamerasButton()
prepareFlashButton()
isTapToFocusEnabled = true
isTapToExposeEnabled = true
}
/// Reloads the view.
open func reloadView() {
// clear constraints so new ones do not conflict
removeConstraints(constraints)
for v in subviews {
v.removeFromSuperview()
}
insertSubview(preview, at: 0)
if let v = captureButton {
insertSubview(v, at: 1)
}
if let v = cameraButton {
insertSubview(v, at: 2)
}
if let v = videoButton {
insertSubview(v, at: 3)
}
}
/// Starts the timer for recording.
internal func startTimer() {
timer?.invalidate()
timer = Timer(timeInterval: 0.5, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
RunLoop.main.add(timer!, forMode: .commonModes)
delegate?.captureDidStartRecordTimer?(capture: self)
}
/// Updates the timer when recording.
internal func updateTimer() {
let duration = session.recordedDuration
let time = CMTimeGetSeconds(duration)
let hours = Int(time / 3600)
let minutes = Int((time / 60).truncatingRemainder(dividingBy: 60))
let seconds = Int(time.truncatingRemainder(dividingBy: 60))
delegate?.captureDidUpdateRecordTimer?(capture: self, hours: hours, minutes: minutes, seconds: seconds)
}
/// Stops the timer when recording.
internal func stopTimer() {
let duration = session.recordedDuration
let time = CMTimeGetSeconds(duration)
let hours = Int(time / 3600)
let minutes = Int((time / 60).truncatingRemainder(dividingBy: 60))
let seconds = Int(time.truncatingRemainder(dividingBy: 60))
timer?.invalidate()
timer = nil
delegate?.captureDidStopRecordTimer?(capture: self, hours: hours, minutes: minutes, seconds: seconds)
open func reload() {
preview.frame = bounds
}
/**
......@@ -432,20 +244,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
*/
@objc
internal func handleCaptureButton(button: UIButton) {
switch captureMode {
case .photo:
session.captureStillImage()
case .video:
if session.isRecording {
session.stopRecording()
stopTimer()
} else {
session.startRecording()
startTimer()
}
}
delegate?.captureDidPressCaptureButton?(capture: self, button: button)
delegate?.captureDidPressCaptureButton?(capture: self, button: button)
}
/**
......@@ -454,7 +253,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
*/
@objc
internal func handleCameraButton(button: UIButton) {
captureMode = .photo
mode = .photo
delegate?.captureDidPressCameraButton?(capture: self, button: button)
}
......@@ -464,7 +263,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
*/
@objc
internal func handleVideoButton(button: UIButton) {
captureMode = .video
mode = .video
delegate?.captureDidPressVideoButton?(capture: self, button: button)
}
......@@ -478,7 +277,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
return
}
let point: CGPoint = recognizer.location(in: self)
let point = recognizer.location(in: self)
session.focus(at: preview.captureDevicePointOfInterestForPoint(point: point))
animateTap(view: focusView!, point: point)
delegate?.captureDidTapToFocusAtPoint?(capture: self, point: point)
......@@ -494,7 +293,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
return
}
let point: CGPoint = recognizer.location(in: self)
let point = recognizer.location(in: self)
session.expose(at: preview.captureDevicePointOfInterestForPoint(point: point))
animateTap(view: exposureView!, point: point)
delegate?.captureDidTapToExposeAtPoint?(capture: self, point: point)
......@@ -512,7 +311,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
session.reset()
let point: CGPoint = preview.pointForCaptureDevicePointOfInterest(point: CGPoint(x: 0.5, y: 0.5))
let point = preview.pointForCaptureDevicePointOfInterest(point: CGPoint(x: 0.5, y: 0.5))
animateTap(view: resetView!, point: point)
delegate?.captureDidTapToResetAtPoint?(capture: self, point: point)
}
......@@ -527,8 +326,11 @@ open class Capture: View, UIGestureRecognizerDelegate {
- Parameter selector: A Selector to handle the event.
*/
private func prepareTapGesture(gesture: inout UITapGestureRecognizer?, numberOfTapsRequired: Int, numberOfTouchesRequired: Int, selector: Selector) {
removeTapGesture(gesture: &gesture)
gesture = UITapGestureRecognizer(target: self, action: selector)
guard nil == gesture else {
return
}
gesture = UITapGestureRecognizer(target: self, action: selector)
gesture!.delegate = self
gesture!.numberOfTapsRequired = numberOfTapsRequired
gesture!.numberOfTouchesRequired = numberOfTouchesRequired
......@@ -554,8 +356,10 @@ open class Capture: View, UIGestureRecognizerDelegate {
}
/// Prepares the preview.
private func preparePreviewView() {
private func preparePreview() {
preview = CapturePreview()
addSubview(preview)
(preview.layer as! AVCaptureVideoPreviewLayer).session = session.session
session.startSession()
}
......@@ -563,26 +367,31 @@ open class Capture: View, UIGestureRecognizerDelegate {
/// Prepares the captureButton.
private func prepareCaptureButton() {
captureButton = FabButton()
captureButton.addTarget(self, action: #selector(handleCaptureButton), for: .touchUpInside)
}
/// Prepares the cameraButton.
private func prepareCameraButton() {
cameraButton = IconButton(image: Icon.cm.photoCamera, tintColor: .white)
cameraButton.addTarget(self, action: #selector(handleCameraButton), for: .touchUpInside)
}
/// Preapres the videoButton.
private func prepareVideoButton() {
videoButton = IconButton(image: Icon.cm.videocam, tintColor: .white)
videoButton.addTarget(self, action: #selector(handleVideoButton), for: .touchUpInside)
}
/// Prepares the switchCameraButton.
private func prepareSwitchCamerasButton() {
switchCamerasButton = IconButton(image: UIImage(named: "ic_camera_front_white"), tintColor: .white)
switchCamerasButton = IconButton(image: Icon.cameraFront, tintColor: .white)
switchCamerasButton.addTarget(self, action: #selector(handleSwitchCamerasButton), for: .touchUpInside)
}
/// Prepares the flashButton.
private func prepareFlashButton() {
flashButton = IconButton(image: UIImage(named: "ic_flash_auto_white"), tintColor: .white)
flashButton = IconButton(image: UIImage(named: Icon.flashAuto, tintColor: .white)
flashButton.addTarget(self, action: #selector(handleFlashButton), for: .touchUpInside)
session.flashMode = .auto
}
......
......@@ -52,6 +52,83 @@ open class CaptureController: ToolbarController, CaptureDelegate, CaptureSession
/// A reference to the Capture instance.
open private(set) lazy var capture: Capture = Capture()
/// A tap gesture reference for focus events.
private var tapToFocusGesture: UITapGestureRecognizer?
/// A tap gesture reference for exposure events.
private var tapToExposeGesture: UITapGestureRecognizer?
/// A tap gesture reference for reset events.
private var tapToResetGesture: UITapGestureRecognizer?
/// A boolean indicating whether to enable tap to focus.
@IBInspectable
open var isTapToFocusEnabled = false {
didSet {
guard isTapToFocusEnabled else {
removeTapGesture(gesture: &tapToFocusGesture)
focusView?.removeFromSuperview()
focusView = nil
return
}
isTapToResetEnabled = true
prepareFocusLayer()
prepareTapGesture(gesture: &tapToFocusGesture, numberOfTapsRequired: 1, numberOfTouchesRequired: 1, selector: #selector(handleTapToFocusGesture))
if let v = tapToExposeGesture {
tapToFocusGesture!.require(toFail: v)
}
}
}
/// A boolean indicating whether to enable tap to expose.
@IBInspectable
open var isTapToExposeEnabled = false {
didSet {
guard isTapToExposeEnabled else {
removeTapGesture(gesture: &tapToExposeGesture)
exposureView?.removeFromSuperview()
exposureView = nil
return
}
isTapToResetEnabled = true
prepareExposureLayer()
prepareTapGesture(gesture: &tapToExposeGesture, numberOfTapsRequired: 2, numberOfTouchesRequired: 1, selector: #selector(handleTapToExposeGesture))
if let v = tapToFocusGesture {
v.require(toFail: tapToExposeGesture!)
}
}
}
/// A boolean indicating whether to enable tap to reset.
@IBInspectable
open var isTapToResetEnabled = false {
didSet {
guard isTapToResetEnabled else {
removeTapGesture(gesture: &tapToResetGesture)
resetView?.removeFromSuperview()
resetView = nil
return
}
prepareResetLayer()
prepareTapGesture(gesture: &tapToResetGesture, numberOfTapsRequired: 2, numberOfTouchesRequired: 2, selector: #selector(handleTapToResetGesture))
if let v = tapToFocusGesture {
v.require(toFail: tapToResetGesture!)
}
if let v = tapToExposeGesture {
v.require(toFail: tapToResetGesture!)
}
}
}
/// A reference to capture's cameraButton.
open var cameraButton: IconButton {
return capture.cameraButton
......@@ -77,6 +154,29 @@ open class CaptureController: ToolbarController, CaptureDelegate, CaptureSession
return capture.captureButton
}
open override func layoutSubviews() {
super.layoutSubviews()
if let v = cameraButton {
v.y = bounds.height - contentEdgeInsets.bottom - v.bounds.height
v.x = contentEdgeInsets.left
}
if let v = captureButton {
v.y = bounds.height - contentEdgeInsets.bottom - v.bounds.height
v.x = (bounds.width - v.width) / 2
}
if let v = videoButton {
v.y = bounds.height - contentEdgeInsets.bottom - v.bounds.height
v.x = bounds.width - v.width - contentEdgeInsets.right
}
if let v = (preview.layer as! AVCaptureVideoPreviewLayer).connection {
v.videoOrientation = session.videoOrientation
}
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
......@@ -109,5 +209,59 @@ open class CaptureController: ToolbarController, CaptureDelegate, CaptureSession
private func prepareCapture() {
capture.delegate = self
capture.session.delegate = self
capture.isTapToFocusEnabled = true
capture.isTapToExposeEnabled = true
}
}
extension CaptureController {
/// Starts the timer for recording.
internal func startTimer() {
timer?.invalidate()
timer = Timer(timeInterval: 0.5, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
RunLoop.main.add(timer!, forMode: .commonModes)
delegate?.captureDidStartRecordTimer?(capture: self)
}
/// Updates the timer when recording.
internal func updateTimer() {
let duration = session.recordedDuration
let time = CMTimeGetSeconds(duration)
let hours = Int(time / 3600)
let minutes = Int((time / 60).truncatingRemainder(dividingBy: 60))
let seconds = Int(time.truncatingRemainder(dividingBy: 60))
delegate?.captureDidUpdateRecordTimer?(capture: self, hours: hours, minutes: minutes, seconds: seconds)
}
/// Stops the timer when recording.
internal func stopTimer() {
let duration = session.recordedDuration
let time = CMTimeGetSeconds(duration)
let hours = Int(time / 3600)
let minutes = Int((time / 60).truncatingRemainder(dividingBy: 60))
let seconds = Int(time.truncatingRemainder(dividingBy: 60))
timer?.invalidate()
timer = nil
delegate?.captureDidStopRecordTimer?(capture: self, hours: hours, minutes: minutes, seconds: seconds)
}
func captureDidPressCaptureButton(capture: Capture, button: UIButton) {
switch captureMode {
case .photo:
session.captureStillImage()
case .video:
if session.isRecording {
session.stopRecording()
stopTimer()
} else {
session.startRecording()
startTimer()
}
}
}
}
......@@ -40,6 +40,7 @@ open class CapturePreview: View {
Converts a point in layer coordinates to a point of interest
in the coordinate space of the capture device providing input
to the layer.
- Parameter point: A CGPoint.
- Returns: A CGPoint that is converted.
*/
open func captureDevicePointOfInterestForPoint(point: CGPoint) -> CGPoint {
......@@ -50,6 +51,7 @@ open class CapturePreview: View {
Converts a point of interest in the coordinate space of the
capture device providing input to the layer to a point in
layer coordinates.
- Parameter point: A CGPoint.
- Returns: A CGPoint that is converted.
*/
open func pointForCaptureDevicePointOfInterest(point: CGPoint) -> CGPoint {
......
......@@ -94,7 +94,7 @@ public protocol CaptureSessionDelegate {
- Parameter error: A Error corresponding to the error.
*/
@objc
optional func sessionFailedWithError(session: CaptureSession, error: Error)
optional func captureSessionFailedWithError(session: CaptureSession, error: Error)
/**
A delegation method that is fired when the camera has been switched to another.
......@@ -102,7 +102,7 @@ public protocol CaptureSessionDelegate {
- Parameter position: An AVCaptureDevicePosition that the camera has switched to.
*/
@objc
optional func sessionDidSwitchCameras(session: CaptureSession, position: AVCaptureDevicePosition)
optional func captureSessionDidSwitchCameras(session: CaptureSession, position: AVCaptureDevicePosition)
/**
A delegation method that is fired before the camera has been switched to another.
......@@ -110,7 +110,7 @@ public protocol CaptureSessionDelegate {
- Parameter position: An AVCaptureDevicePosition that the camera will switch to.
*/
@objc
optional func sessionWillSwitchCameras(session: CaptureSession, position: AVCaptureDevicePosition)
optional func captureSessionWillSwitchCameras(session: CaptureSession, position: AVCaptureDevicePosition)
/**
A delegation method that is fired when an image has been captured asynchronously.
......@@ -118,7 +118,7 @@ public protocol CaptureSessionDelegate {
- Parameter image: An image that has been captured.
*/
@objc
optional func sessionStillImageAsynchronously(session: CaptureSession, image: UIImage)
optional func captureSessionStillImageAsynchronously(session: CaptureSession, image: UIImage)
/**
A delegation method that is fired when capturing an image asynchronously has failed.
......@@ -126,7 +126,7 @@ public protocol CaptureSessionDelegate {
- Parameter error: A Error corresponding to the error.
*/
@objc
optional func sessionStillImageAsynchronouslyFailedWithError(session: CaptureSession, error: Error)
optional func captureSessionStillImageAsynchronouslyFailedWithError(session: CaptureSession, error: Error)
/**
A delegation method that is fired when creating a movie file has failed.
......@@ -134,7 +134,7 @@ public protocol CaptureSessionDelegate {
- Parameter error: A Error corresponding to the error.
*/
@objc
optional func sessionCreateMovieFileFailedWithError(session: CaptureSession, error: Error)
optional func captureSessionCreateMovieFileFailedWithError(session: CaptureSession, error: Error)
/**
A delegation method that is fired when capturing a movie has failed.
......@@ -142,7 +142,7 @@ public protocol CaptureSessionDelegate {
- Parameter error: A Error corresponding to the error.
*/
@objc
optional func sessionMovieFailedWithError(session: CaptureSession, error: Error)
optional func captureSessionMovieFailedWithError(session: CaptureSession, error: Error)
/**
A delegation method that is fired when a session started recording and writing
......@@ -153,7 +153,7 @@ public protocol CaptureSessionDelegate {
- Parameter fromConnections: An array of Anys.
*/
@objc
optional func sessionDidStartRecordingToOutputFileAtURL(session: CaptureSession, captureOutput: AVCaptureFileOutput, fileURL: NSURL, fromConnections connections: [Any])
optional func captureSessionDidStartRecordingToOutputFileAtURL(session: CaptureSession, captureOutput: AVCaptureFileOutput, fileURL: NSURL, fromConnections connections: [Any])
/**
A delegation method that is fired when a session finished recording and writing
......@@ -165,7 +165,7 @@ public protocol CaptureSessionDelegate {
- Parameter error: A Error corresponding to an error.
*/
@objc
optional func sessionDidFinishRecordingToOutputFileAtURL(session: CaptureSession, captureOutput: AVCaptureFileOutput, outputFileURL: NSURL, fromConnections connections: [Any], error: Error!)
optional func captureSessionDidFinishRecordingToOutputFileAtURL(session: CaptureSession, captureOutput: AVCaptureFileOutput, outputFileURL: NSURL, fromConnections connections: [Any], error: Error!)
}
@objc(CaptureSession)
......@@ -241,12 +241,12 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
}
/// A boolean indicating if the active camera has flash.
open var hasFlash: Bool {
open var isFlashAvailable: Bool {
return nil == activeCamera ? false : activeCamera!.hasFlash
}
/// A boolean indicating if the active camera has a torch.
open var hasTorch: Bool {
open var isTorchAvailable: Bool {
return nil == activeCamera ? false : activeCamera!.hasTorch
}
......@@ -280,7 +280,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
}
if let e = error {
delegate?.sessionFailedWithError?(session: self, error: e)
delegate?.captureSessionFailedWithError?(session: self, error: e)
}
}
}
......@@ -310,7 +310,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
}
if let e = error {
delegate?.sessionFailedWithError?(session: self, error: e)
delegate?.captureSessionFailedWithError?(session: self, error: e)
}
}
}
......@@ -340,7 +340,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
}
if let e = error {
delegate?.sessionFailedWithError?(session: self, error: e)
delegate?.captureSessionFailedWithError?(session: self, error: e)
}
}
}
......@@ -417,7 +417,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
return
}
delegate?.sessionWillSwitchCameras?(session: self, position: v)
delegate?.captureSessionWillSwitchCameras?(session: self, position: v)
let videoInput: AVCaptureDeviceInput? = try AVCaptureDeviceInput(device: inactiveCamera!)
session.beginConfiguration()
......@@ -431,9 +431,9 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
}
session.commitConfiguration()
delegate?.sessionDidSwitchCameras?(session: self, position: position!)
delegate?.captureSessionDidSwitchCameras?(session: self, position: position!)
} catch let e as NSError {
delegate?.sessionFailedWithError?(session: self, error: e)
delegate?.captureSessionFailedWithError?(session: self, error: e)
}
}
......@@ -481,7 +481,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
var error: NSError?
if isFocusPointOfInterestSupported && isFocusModeSupported(focusMode: .autoFocus) {
do {
let device: AVCaptureDevice = activeCamera!
let device = activeCamera!
try device.lockForConfiguration()
device.focusPointOfInterest = point
device.focusMode = .autoFocus
......@@ -490,7 +490,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
error = e
}
} else {
var userInfo: Dictionary<String, Any> = Dictionary<String, Any>()
var userInfo = [String: Any]()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported focus.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported focus.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0004, userInfo: userInfo)
......@@ -498,7 +498,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
}
if let e = error {
delegate?.sessionFailedWithError?(session: self, error: e)
delegate?.captureSessionFailedWithError?(session: self, error: e)
}
}
......@@ -510,7 +510,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
var error: NSError?
if isExposurePointOfInterestSupported && isExposureModeSupported(exposureMode: .continuousAutoExposure) {
do {
let device: AVCaptureDevice = activeCamera!
let device = activeCamera!
try device.lockForConfiguration()
device.exposurePointOfInterest = point
device.exposureMode = .continuousAutoExposure
......@@ -522,7 +522,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
error = e
}
} else {
var userInfo: Dictionary<String, Any> = Dictionary<String, Any>()
var userInfo = [String: Any]()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported expose.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported expose.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0005, userInfo: userInfo)
......@@ -530,13 +530,13 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
}
if let e = error {
delegate?.sessionFailedWithError?(session: self, error: e)
delegate?.captureSessionFailedWithError?(session: self, error: e)
}
}
open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
if context == &CaptureSessionAdjustingExposureContext {
let device: AVCaptureDevice = object as! AVCaptureDevice
let device = object as! AVCaptureDevice
if !device.isAdjustingExposure && device.isExposureModeSupported(.locked) {
(object! as AnyObject).removeObserver(self, forKeyPath: "adjustingExposure", context: &CaptureSessionAdjustingExposureContext)
DispatchQueue.main.async() {
......@@ -545,7 +545,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
device.exposureMode = .locked
device.unlockForConfiguration()
} catch let e as NSError {
self.delegate?.sessionFailedWithError?(session: self, error: e)
self.delegate?.captureSessionFailedWithError?(session: self, error: e)
}
}
}
......@@ -560,10 +560,10 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
- Parameter exposure: A boolean indicating to reset the exposure.
*/
open func reset(focus: Bool = true, exposure: Bool = true) {
let device: AVCaptureDevice = activeCamera!
let canResetFocus: Bool = device.isFocusPointOfInterestSupported && device.isFocusModeSupported(.continuousAutoFocus)
let canResetExposure: Bool = device.isExposurePointOfInterestSupported && device.isExposureModeSupported(.continuousAutoExposure)
let centerPoint: CGPoint = CGPoint(x: 0.5, y: 0.5)
let device = activeCamera!
let canResetFocus = device.isFocusPointOfInterestSupported && device.isFocusModeSupported(.continuousAutoFocus)
let canResetExposure = device.isExposurePointOfInterestSupported && device.isExposureModeSupported(.continuousAutoExposure)
let centerPoint = CGPoint(x: 0.5, y: 0.5)
do {
try device.lockForConfiguration()
......@@ -579,7 +579,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
device.unlockForConfiguration()
} catch let e as NSError {
delegate?.sessionFailedWithError?(session: self, error: e)
delegate?.captureSessionFailedWithError?(session: self, error: e)
}
}
......@@ -606,7 +606,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
if let image1 = UIImage(data: data) {
if let image2 = image1.adjustOrientation() {
s.delegate?.sessionStillImageAsynchronously?(session: s, image: image2)
s.delegate?.captureSessionStillImageAsynchronously?(session: s, image: image2)
} else {
var userInfo = [String: Any]()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Cannot fix image orientation.]"
......@@ -624,7 +624,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
}
if let e = captureError {
s.delegate?.sessionStillImageAsynchronouslyFailedWithError?(session: s, error: e)
s.delegate?.captureSessionStillImageAsynchronouslyFailedWithError?(session: s, error: e)
}
}
}
......@@ -653,7 +653,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
v.isSmoothAutoFocusEnabled = true
v.unlockForConfiguration()
} catch let e as NSError {
s.delegate?.sessionFailedWithError?(session: s, error: e)
s.delegate?.captureSessionFailedWithError?(session: s, error: e)
}
}
......@@ -676,12 +676,12 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
public func capture(_ captureOutput: AVCaptureFileOutput!, didStartRecordingToOutputFileAt fileURL: URL!, fromConnections connections: [Any]!) {
isRecording = true
delegate?.sessionDidStartRecordingToOutputFileAtURL?(session: self, captureOutput: captureOutput, fileURL: fileURL as NSURL, fromConnections: connections)
delegate?.captureSessionDidStartRecordingToOutputFileAtURL?(session: self, captureOutput: captureOutput, fileURL: fileURL as NSURL, fromConnections: connections)
}
public func capture(_ captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAt outputFileURL: URL!, fromConnections connections: [Any]!, error: Error!) {
isRecording = false
delegate?.sessionDidFinishRecordingToOutputFileAtURL?(session: self, captureOutput: captureOutput, outputFileURL: outputFileURL as NSURL, fromConnections: connections, error: error)
delegate?.captureSessionDidFinishRecordingToOutputFileAtURL?(session: self, captureOutput: captureOutput, outputFileURL: outputFileURL as NSURL, fromConnections: connections, error: error)
}
/// Prepares the sessionQueue.
......@@ -705,7 +705,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
session.addInput(activeVideoInput)
} catch let e as NSError {
delegate?.sessionFailedWithError?(session: self, error: e)
delegate?.captureSessionFailedWithError?(session: self, error: e)
}
}
......@@ -720,7 +720,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
session.addInput(activeAudioInput)
} catch let e as NSError {
delegate?.sessionFailedWithError?(session: self, error: e)
delegate?.captureSessionFailedWithError?(session: self, error: e)
}
}
......@@ -776,7 +776,7 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
return directory.appendingPathComponent(dateFormatter.string(from: NSDate() as Date) + ".mov")
} catch let e as NSError {
delegate?.sessionCreateMovieFileFailedWithError?(session: self, error: e)
delegate?.captureSessionCreateMovieFileFailedWithError?(session: self, error: e)
}
return nil
}
......
......@@ -63,14 +63,19 @@ public struct Icon {
public static let arrowDownward = Icon.icon("ic_arrow_downward_white")
public static let audio = Icon.icon("ic_audiotrack_white")
public static let bell = Icon.icon("cm_bell_white")
public static let check = Icon.icon("ic_check_white")
public static let cameraFront = Icon.icon("ic_camera_front_white")
public static let cameraRear = Icon.icon("ic_camera_rear_white")
public static let check = Icon.icon("ic_check_white")
public static let clear = Icon.icon("ic_close_white")
public static let close = Icon.icon("ic_close_white")
public static let edit = Icon.icon("ic_edit_white")
public static let email = Icon.icon("ic_email_white")
public static let favorite = Icon.icon("ic_favorite_white")
public static let favoriteBorder = Icon.icon("ic_favorite_border_white")
public static let history = Icon.icon("ic_history_white")
public static let flashAuto = Icon.icon("ic_flash_auto_white")
public static let flashOff = Icon.icon("ic_flash_off_white")
public static let flashOn = Icon.icon("ic_flash_on_white")
public static let history = Icon.icon("ic_history_white")
public static let home = Icon.icon("ic_home_white")
public static let image = Icon.icon("ic_image_white")
public static let menu = Icon.icon("ic_menu_white")
......@@ -81,6 +86,7 @@ public struct Icon {
public static let place = Icon.icon("ic_place_white")
public static let phone = Icon.icon("ic_phone_white")
public static let photoCamera = Icon.icon("ic_photo_camera_white")
public static let photoCameraLarge = Icon.icon("ic_photo_camera_white_36pt")
public static let photoLibrary = Icon.icon("ic_photo_library_white")
public static let search = Icon.icon("ic_search_white")
public static let settings = Icon.icon("ic_settings_white")
......@@ -89,6 +95,7 @@ public struct Icon {
public static let starBorder = Icon.icon("ic_star_border_white")
public static let starHalf = Icon.icon("ic_star_half_white")
public static let videocam = Icon.icon("ic_videocam_white")
public static let videocamLarge = Icon.icon("ic_videocam_white_36pt")
public static let visibility = Icon.icon("ic_visibility_white")
/// CosmicMind icons.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment