Skip to content

mihailsalari/macOS-Camera

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

macOS-Camera

Simple example how to run macOS Camera

Demo

Camera

AVFoundation

https://developer.apple.com/av-foundation/

Support

[8.x.x] [7.x.x]
Xcode Version x

Supporting macOS version:

  • macOS 10.x

Feature Done

v1.0.0

  • AVCaptureVideoPreviewLayer
  • AVCaptureSession
  • AVCaptureDevice

v2.0.0

  • CameraManagerProtocol
  • CameraManager
  • CameraManagerDelegate

Usage:

  1. Drag and drop the CameraManager.swift into your macOS Xcode project.

On viewDidLoad method, instantiate the CameraManager object:

    do {
      cameraManager = try CameraManager(containerView: view)
    } catch {
      // Cath the error here
    }
  1. Set the CameraManagerDelegate

After you instantiated the camera manager, set it's delegate in this way:

    cameraManager.delegate = self
  1. To start camera, run the following snippet on viewDidLoad or viewDidAppear method:
    do {
      try cameraManager.startSession()
    } catch {
      // Cath the error here
    }

Full snippet code:

      private var cameraManager: CameraManagerProtocol!
  
  override func viewDidLoad() {
    super.viewDidLoad()
    do {
      cameraManager = try CameraManager(containerView: view)
      cameraManager.delegate = self
    } catch {
      // Cath the error here
      print(error.localizedDescription)
    }
  }
  
  override var representedObject: Any? {
    didSet {
      // Update the view, if already loaded.
    }
  }
  
  override func viewDidAppear() {
    super.viewDidAppear()
    do {
      try cameraManager.startSession()
    } catch {
      // Cath the error here
      print(error.localizedDescription)
    }
  }
  
  override func viewDidDisappear() {
    super.viewDidDisappear()
    do {
      try cameraManager.stopSession()
    } catch {
      // Cath the error here
      print(error.localizedDescription)
    }
  }
    extension YourViewController: CameraManagerDelegate {
        func cameraManager(_ output: CameraCaptureOutput, didOutput sampleBuffer: CameraSampleBuffer, 
                             from connection: CameraCaptureConnection) {
            print(Date())
        }
    }

Bug Reports & Feature Requests

No Bugs

Contributing

  1. Fork the project.
  2. Create a branch for your new feature.
  3. Write tests.
  4. Write code to make the tests pass.
  5. Submit a pull request.

All pull requests are welcome !

About

Simple example how to run macOS Camera

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages