Skip to content

Instantly share code, notes, and snippets.

@hewigovens
Created July 13, 2019 08:56
Show Gist options
  • Save hewigovens/c9e9826c93820fa2459963ea71c4fff9 to your computer and use it in GitHub Desktop.
Save hewigovens/c9e9826c93820fa2459963ea71c4fff9 to your computer and use it in GitHub Desktop.
DynoPaper
import Cocoa
import AVKit
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
var videoWindow: NSWindow!
var playerLooper: AVPlayerLooper?
func applicationDidFinishLaunching(_ aNotification: Notification) {
window.orderOut(nil)
let url = Bundle.main.url(forResource: "sakura", withExtension: "mp4")!
let frame = NSScreen.main!.frame
let player = AVQueuePlayer()
let layer = AVPlayerLayer(player: player)
let playerItem = AVPlayerItem(url: url)
playerLooper = AVPlayerLooper(player: player, templateItem: playerItem)
layer.frame = CGRect(x: 0, y: 0, width: frame.width, height: frame.height)
videoWindow = NSWindow(contentRect: frame, styleMask: .borderless, backing: .buffered, defer: false)
videoWindow.collectionBehavior = .canJoinAllSpaces
videoWindow.level = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(CGWindowLevelKey.desktopWindow)))
videoWindow.orderFront(nil)
videoWindow.backgroundColor = NSColor.clear
videoWindow.contentView?.wantsLayer = true
videoWindow.contentView?.layer?.addSublayer(layer)
player.play()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment