-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathVideoWindow.swift
78 lines (59 loc) · 2.5 KB
/
VideoWindow.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import Cocoa
class VideoWindow: NSWindow, NSWindowDelegate {
var vlayer: VideoLayer?
var vview: VideoView?
var windowFrame: NSRect?
override var canBecomeKey: Bool { return true }
override var canBecomeMain: Bool { return true }
override init(contentRect: NSRect, styleMask style: NSWindow.StyleMask,
backing backingStoreType: NSWindow.BackingStoreType, defer flag: Bool) {
super.init(contentRect:contentRect, styleMask:style, backing:backingStoreType, defer:flag)
title = "test"
minSize = NSMakeSize(200, 200)
makeMain()
makeKeyAndOrderFront(nil)
delegate = self
contentAspectRatio = contentView!.frame.size
windowFrame = convertToScreen(contentView!.frame)
vview = VideoView(frame: contentView!.bounds)
contentView!.addSubview(vview!)
vlayer = VideoLayer()
vview!.layer = vlayer
vview!.wantsLayer = true
}
func windowWillStartLiveResize(_ notification: Notification) {
vlayer!.inLiveResize = true
}
func windowDidEndLiveResize(_ notification: Notification) {
vlayer!.inLiveResize = false
}
func customWindowsToEnterFullScreen(for window: NSWindow) -> [NSWindow]? {
return [window]
}
func customWindowsToExitFullScreen(for window: NSWindow) -> [NSWindow]? {
return [window]
}
func window(_ window: NSWindow, startCustomAnimationToEnterFullScreenWithDuration duration: TimeInterval) {
windowFrame = convertToScreen(contentView!.frame)
NSAnimationContext.runAnimationGroup({ (context) -> Void in
context.duration = duration*0.9
window.animator().setFrame(screen!.frame, display: true)
}, completionHandler: { })
}
func window(_ window: NSWindow, startCustomAnimationToExitFullScreenWithDuration duration: TimeInterval) {
NSAnimationContext.runAnimationGroup({ (context) -> Void in
context.duration = duration*0.9
window.animator().setFrame(windowFrame!, display: true)
}, completionHandler: { })
}
func windowDidEnterFullScreen(_ notification: Notification) {}
func windowDidExitFullScreen(_ notification: Notification) {
contentAspectRatio = windowFrame!.size
}
func windowDidFailToEnterFullScreen(_ window: NSWindow) {}
func windowDidFailToExitFullScreen(_ window: NSWindow) {}
func windowShouldClose(_ sender: NSWindow) -> Bool {
vlayer!.uninitMPV()
return false
}
}