-
Notifications
You must be signed in to change notification settings - Fork 0
/
avtest.swift
38 lines (31 loc) · 1.03 KB
/
avtest.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// 2 april 2016
import Cocoa
import AVFoundation
import AVKit
class appDelegate : NSObject, NSApplicationDelegate {
func applicationShouldTerminateAfterLastWindowClosed(app: NSApplication) -> Bool {
return true
}
}
var app = NSApplication.sharedApplication()
app.setActivationPolicy(.Regular)
var ad = appDelegate()
app.delegate = ad
var mainwin = NSWindow(contentRect: NSMakeRect(0, 0, 800, 600),
styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask,
backing: .Buffered,
defer: true)
var session = AVCaptureSession()
session.sessionPreset = AVCaptureSessionPresetPhoto
var device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
var input = try! AVCaptureDeviceInput(device: device)
session.addInput(input)
session.startRunning()
var avv = NSView(frame: NSMakeRect(20, 20, 760, 560))
mainwin.contentView?.addSubview(avv)
var avl = AVCaptureVideoPreviewLayer(session: session)
avv.layer = avl
avv.wantsLayer = true
mainwin.center()
mainwin.makeKeyAndOrderFront(nil)
app.run()