forked from JohnCoates/Aerial
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More cleanup, revert the isPreview thing that is NOT fixed in Catalin…
…a, unlike what I thought. Should not have closed that radar :(
- Loading branch information
Showing
9 changed files
with
209 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// | ||
// AerialView+Player.swift | ||
// Aerial | ||
// | ||
// Created by Guillaume Louel on 06/12/2019. | ||
// Copyright © 2019 John Coates. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import AVFoundation | ||
import AVKit | ||
|
||
extension AerialView { | ||
func setupPlayerLayer(withPlayer player: AVPlayer) { | ||
let displayDetection = DisplayDetection.sharedInstance | ||
let preferences = Preferences.sharedInstance | ||
|
||
self.layer = CALayer() | ||
guard let layer = self.layer else { | ||
errorLog("\(self.description) Couldn't create CALayer") | ||
return | ||
} | ||
self.wantsLayer = true | ||
layer.backgroundColor = NSColor.black.cgColor | ||
layer.needsDisplayOnBoundsChange = true | ||
layer.frame = self.bounds | ||
debugLog("\(self.description) setting up player layer with bounds/frame: \(layer.bounds) / \(layer.frame)") | ||
|
||
playerLayer = AVPlayerLayer(player: player) | ||
|
||
if #available(OSX 10.10, *) { | ||
if preferences.aspectMode == Preferences.AspectMode.fill.rawValue { | ||
playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill | ||
} else { | ||
playerLayer.videoGravity = AVLayerVideoGravity.resizeAspect | ||
} | ||
} | ||
playerLayer.autoresizingMask = [CAAutoresizingMask.layerWidthSizable, CAAutoresizingMask.layerHeightSizable] | ||
|
||
// In case of span mode we need to compute the size of our layer | ||
if preferences.newViewingMode == Preferences.NewViewingMode.spanned.rawValue && !isPreview { | ||
let zRect = displayDetection.getZeroedActiveSpannedRect() | ||
let screen = displayDetection.findScreenWith(frame: self.frame) | ||
if let scr = screen { | ||
let tRect = CGRect(x: zRect.origin.x - scr.zeroedOrigin.x, | ||
y: zRect.origin.y - scr.zeroedOrigin.y, | ||
width: zRect.width, | ||
height: zRect.height) | ||
playerLayer.frame = tRect | ||
} else { | ||
errorLog("This is an unknown screen in span mode, this is not good") | ||
playerLayer.frame = layer.bounds | ||
} | ||
} else { | ||
playerLayer.frame = layer.bounds | ||
|
||
// "true" mirrored mode | ||
let index = AerialView.instanciatedViews.firstIndex(of: self) ?? 0 | ||
if index % 2 == 1 && preferences.newViewingMode == Preferences.NewViewingMode.mirrored.rawValue { | ||
playerLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransform(scaleX: -1, y: 1)) | ||
} | ||
} | ||
layer.addSublayer(playerLayer) | ||
|
||
// The layers for descriptions, clock, message | ||
setupTextLayers(layer: layer) | ||
|
||
// An extra layer to try and contravent a macOS graphics driver bug | ||
// This is useful on High Sierra+ on Intel Macs | ||
setupGlitchWorkaroundLayer(layer: layer) | ||
} | ||
|
||
// MARK: - AVPlayerItem Notifications | ||
|
||
@objc func playerItemFailedtoPlayToEnd(_ aNotification: Notification) { | ||
warnLog("\(self.description) AVPlayerItemFailedToPlayToEndTimeNotification \(aNotification)") | ||
playNextVideo() | ||
} | ||
|
||
@objc func playerItemNewErrorLogEntryNotification(_ aNotification: Notification) { | ||
warnLog("\(self.description) AVPlayerItemNewErrorLogEntryNotification \(aNotification)") | ||
} | ||
|
||
@objc func playerItemPlaybackStalledNotification(_ aNotification: Notification) { | ||
warnLog("\(self.description) AVPlayerItemPlaybackStalledNotification \(aNotification)") | ||
} | ||
|
||
@objc func playerItemDidReachEnd(_ aNotification: Notification) { | ||
debugLog("\(self.description) played did reach end") | ||
debugLog("\(self.description) notification: \(aNotification)") | ||
playNextVideo() | ||
debugLog("\(self.description) playing next video for player \(String(describing: player))") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// AerialView+Text.swift | ||
// Aerial | ||
// | ||
// Created by Guillaume Louel on 06/12/2019. | ||
// Copyright © 2019 John Coates. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import AVKit | ||
|
||
extension AerialView { | ||
|
||
func setupTextLayers(layer: CALayer) { | ||
// Main description layer | ||
textLayer = CATextLayer() | ||
textLayer.frame = layer.bounds // Same size as the screen | ||
textLayer.opacity = 0 | ||
textLayer.shadowRadius = 10 | ||
textLayer.shadowOpacity = 1.0 | ||
textLayer.shadowColor = CGColor.black | ||
layer.addSublayer(textLayer) | ||
|
||
// Clock Layer | ||
clockLayer = CATextLayer() | ||
clockLayer.opacity = 0 | ||
clockLayer.shadowRadius = 10 | ||
clockLayer.shadowOpacity = 1.0 | ||
clockLayer.shadowColor = CGColor.black | ||
layer.addSublayer(clockLayer) | ||
|
||
// Message Layer | ||
messageLayer = CATextLayer() | ||
messageLayer.opacity = 0 | ||
messageLayer.shadowRadius = 10 | ||
messageLayer.shadowOpacity = 1.0 | ||
messageLayer.shadowColor = CGColor.black | ||
layer.addSublayer(messageLayer) | ||
} | ||
|
||
func setupGlitchWorkaroundLayer(layer: CALayer) { | ||
debugLog("Using dot workaround for video driver corruption") | ||
|
||
let workaroundLayer = CATextLayer() | ||
workaroundLayer.frame = self.bounds | ||
workaroundLayer.opacity = 0.5 | ||
workaroundLayer.font = NSFont(name: "Helvetica Neue Medium", size: 4) | ||
workaroundLayer.fontSize = 4 | ||
workaroundLayer.string = "." | ||
|
||
let attributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: workaroundLayer.font as Any] | ||
|
||
// Calculate bounding box | ||
let attrString = NSAttributedString(string: workaroundLayer.string as! String, attributes: attributes) | ||
let rect = attrString.boundingRect(with: layer.visibleRect.size, options: NSString.DrawingOptions.usesLineFragmentOrigin) | ||
|
||
workaroundLayer.frame = rect | ||
workaroundLayer.position = CGPoint(x: 2, y: 2) | ||
workaroundLayer.anchorPoint = CGPoint(x: 0, y: 0) | ||
layer.addSublayer(workaroundLayer) | ||
} | ||
} |
Oops, something went wrong.