Swiftpack.co - magesteve/MSCaptureView as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by magesteve.
magesteve/MSCaptureView 1.0.0
NSView subclass to capture video/audio from a Mac internal camera & microphone
⭐️ 8
🕓 3 years ago
macOS
.package(url: "https://github.com/magesteve/MSCaptureView.git", from: "1.0.0")

MSCaptureView - NSView subclass to capture video/audio from a Mac internal camera & microphone.

AVFoundation provides all the tools a programmer needs to capture video & audio generated by the Camera and Microphone of a Mac or IOS program. AVCaptureView, part of AVKit, provides a View for displaying the video input and capturing the output to a file. The developer still has to write considerable code to connect the two parts. On the iOS side, Apple provides the often used UIImagePickerController class to combine all the components required to capture video and audio. Surprisingly, there is no such View or Controller on the Mac platform.

Now there is.

MSCaptureView can be used to give simple movie capture ability to any Mac program. Only a few calls are needed to set up the capture. All the functionality is encapsulated with the View, with simple calls to turn the capture on or off.

Installation

Since MSCaptureView is a Swift Package, the IDE or Make file of a project must reference MSCaptureView's repository:

https://github.com/magesteve/MSCaptureView

To clone MSCaptureView, the following Terminal command should be used:

% git clone https://github.com/magesteve/MSCaptureView.git

Platform Specific Usage

MSCaptureView is a NSVIew class; thus it must be added to a programs NSVIewController or NSWindowController. Use Interface Builder to add a generic NSView to the Interface of the App (XIB or Storyboard files). Then change the Views type to MSCaptureView. Create an IBOutlet reference between the view and its controller.

When the program starts, invoke the requestCaptureAuthorization() function so that app asks the user for permission to use the Camera & Microphone. When the view appears, call the showPreview() function to start the video preview. At some point, use the use(url) function to set the output location for the movie to be created. The startCapture() function starts recording to the movie file, while the stopCapture() function halts it. Swift closures can be used to inform the app of state changes by the view (ex: Authorization succeeded, start Movie recording, stop Movie recording).

Documentation

All public classes, protocols, properties & functions have inline documentation (DOxygen style). Further explanation of the Framework, refer to the MSCaptureView-Demo repository or any example projects.

https://github.com/magesteve/MSCaptureView-Demo

Requirements

MSCaptureView requires specific changes to the MacOS program it is running within.

  1. Add NSCameraUsageDescription & NSMicrophoneUsageDescription to Info.plist. (ex: "This app requires the Camera for video capture.")
  2. Add AVFoundation Framework.
  3. Add Sandbox access to Hardware Camera and Audio Input,
  4. Add Sandbox access File Access for the Movie Folder set to Read/Write.

Versions

1.0.0 Initial Release

Future

I would like to add an optional HUD so that start and stop can be done directly within the preview.

Steve Sheets, [email protected]

Originally from Silicon Valley, Steve has been embedded in the software industry for over 35 years. As an expert in user interface and design, he started developer desktop applications for companies like Apple and AOL, moved into mobile development, and is now working in the virtual reality and Augment Reality space. He has taught Objective-C & Swift development classes (MoDev, Learning Tree), as well as given talk on variety of developer topics (DC Mac Dev group, Capital One Swift Conference). He is an avid game player, swordsman and an occasional game designer.

License

MSCaptureView is available under the MIT license. The intent of the project is to be always Open Source and freely available. Please keep me informed of any interesting uses!

GitHub

link
Stars: 8
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v1.0.0
3 years ago

Initial Release of MSCaptureView

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics