Skip to content

Commit

Permalink
Merge pull request #787 from glouel/1.5.0exp
Browse files Browse the repository at this point in the history
1.5.0exp
  • Loading branch information
glouel authored May 29, 2019
2 parents 0a3db5a + 6fa488c commit 73c20d0
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 18 deletions.
41 changes: 40 additions & 1 deletion Aerial/Source/Controllers/CustomVideoController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@ class CustomVideoController: NSWindowController, NSWindowDelegate {

@IBOutlet var addPoiPopover: NSPopover!
@IBOutlet var timeTextField: NSTextField!
@IBOutlet var timeTextStepper: NSStepper!
@IBOutlet var timeTextFormatter: NumberFormatter!
@IBOutlet var descriptionTextField: NSTextField!

@IBOutlet var durationLabel: NSTextField!
@IBOutlet var resolutionLabel: NSTextField!

var currentFolder: Folder?
var currentAsset: Asset?
var currentAssetDuration: Int?

var hasAwokenAlready = false
var sw: NSWindow?
var controller: PreferencesWindowController?
Expand Down Expand Up @@ -78,7 +85,7 @@ class CustomVideoController: NSWindowController, NSWindowDelegate {

manifestInstance.addCallback { manifestVideos in
if let contr = self.controller {
contr.loaded(manifestVideos: manifestVideos)
contr.loaded(manifestVideos: [])
}
}
manifestInstance.loadManifestsFromLoadedFiles()
Expand Down Expand Up @@ -219,6 +226,18 @@ class CustomVideoController: NSWindowController, NSWindowDelegate {
}
}

@IBAction func timeStepperChange(_ sender: NSStepper) {
if let player = editPlayerView.player {
player.seek(to: CMTime(seconds: Double(sender.intValue), preferredTimescale: 1))
}
}

@IBAction func timeTextChange(_ sender: NSTextField) {
if let player = editPlayerView.player {
player.seek(to: CMTime(seconds: Double(sender.intValue), preferredTimescale: 1))
}
}

@IBAction func tableViewTimeField(_ sender: NSTextField) {
if let asset = currentAsset {
if poiTableView.selectedRow != -1 {
Expand Down Expand Up @@ -338,6 +357,20 @@ extension CustomVideoController: NSOutlineViewDelegate {

if let player = editPlayerView.player {
let localitem = AVPlayerItem(url: URL(fileURLWithPath: file.url))
currentAssetDuration = Int(localitem.asset.duration.convertScale(1, method: .default).value)
let currentResolution = getResolution(asset: localitem.asset)
let crString = String(Int(currentResolution.width)) + "x" + String(Int(currentResolution.height))

timeTextStepper.minValue = 0
timeTextStepper.maxValue = Double(currentAssetDuration!)
timeTextFormatter.minimum = 0
timeTextFormatter.maximum = NSNumber(value: currentAssetDuration!)
//timeTableFormatter.minimum = 0
//timeTableFormatter.maximum = NSNumber(value: currentAssetDuration!)

durationLabel.stringValue = String(currentAssetDuration!) + " seconds"
resolutionLabel.stringValue = crString

player.replaceCurrentItem(with: localitem)
}

Expand All @@ -350,6 +383,12 @@ extension CustomVideoController: NSOutlineViewDelegate {

return true
}

func getResolution(asset: AVAsset) -> CGSize {
guard let track = asset.tracks(withMediaType: AVMediaType.video).first else { return CGSize.zero }
let size = track.naturalSize.applying(track.preferredTransform)
return CGSize(width: abs(size.width), height: abs(size.height))
}
}

// MARK: - Extension for poi table view
Expand Down
7 changes: 6 additions & 1 deletion Aerial/Source/Controllers/PreferencesWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1971,8 +1971,12 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo
var videos = [AerialVideo]()
var cities = [String: City]()

// Grab a fresh version, because our callback can be feeding us wrong data in CVC
let freshManifestVideos = ManifestLoader.instance.loadedManifest
//debugLog("freshManifestVideos count : \(freshManifestVideos.count)")

// First day, then night
for video in manifestVideos {
for video in freshManifestVideos {
let name = video.name

if cities.keys.contains(name) == false {
Expand Down Expand Up @@ -2183,6 +2187,7 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo
case let video as AerialVideo:
player = AVPlayer()
playerView.player = player
player.isMuted = true

debugLog("Playing this preview \(video)")
// Workaround for cached videos generating online traffic
Expand Down
1 change: 1 addition & 0 deletions Aerial/Source/Models/CustomVideoFolders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func newJSONDecoder() -> JSONDecoder {

func newJSONEncoder() -> JSONEncoder {
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
if #available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
encoder.dateEncodingStrategy = .iso8601
}
Expand Down
24 changes: 21 additions & 3 deletions Aerial/Source/Models/ManifestLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation
import ScreenSaver
import GameplayKit
import AVFoundation

typealias ManifestLoadCallback = ([AerialVideo]) -> Void

Expand Down Expand Up @@ -410,6 +411,7 @@ class ManifestLoader {
if let encodedData = try? cvf.jsonData() {
try encodedData.write(to: cacheFileUrl)
debugLog("customvideos.json saved successfully!")
loadedManifest.removeAll() // we remove our previously loaded manifest, it's invalid
}
} catch let error as NSError {
errorLog("customvideos.json could not be saved: \(error.localizedDescription)")
Expand All @@ -422,14 +424,24 @@ class ManifestLoader {
if let cvf = customVideoFolders {
for folder in cvf.folders {
for asset in folder.assets {
let avResolution = getResolution(asset: AVAsset(url: URL(fileURLWithPath: asset.url)))
var url1080p = ""
var url4K = ""

if avResolution.height > 1080 {
url4K = URL(fileURLWithPath: asset.url).absoluteString
} else {
url1080p = URL(fileURLWithPath: asset.url).absoluteString
}

let video = AerialVideo(id: asset.id,
name: folder.label,
secondaryName: asset.accessibilityLabel,
type: "video",
timeOfDay: asset.time,
url1080pH264: URL(fileURLWithPath: asset.url).absoluteString,
url1080pH264: url1080p,
url1080pHEVC: "",
url4KHEVC: "",
url4KHEVC: url4K,
manifest: .customVideos,
poi: [:],
communityPoi: asset.pointsOfInterest)
Expand All @@ -439,6 +451,12 @@ class ManifestLoader {
}
}

func getResolution(asset: AVAsset) -> CGSize {
guard let track = asset.tracks(withMediaType: AVMediaType.video).first else { return CGSize.zero }
let size = track.naturalSize.applying(track.preferredTransform)
return CGSize(width: abs(size.width), height: abs(size.height))
}

// MARK: - Periodically check for new videos
func checkIfShouldRedownloadFiles() {
let dateFormatter = DateFormatter()
Expand Down Expand Up @@ -641,7 +659,7 @@ class ManifestLoader {
}
}*/

debugLog("Total videos processed : \(processedVideos.count)")
debugLog("Total videos processed : \(processedVideos.count) callbacks : \(callbacks.count)")
// callbacks
for callback in self.callbacks {
callback(self.loadedManifest)
Expand Down
1 change: 1 addition & 0 deletions Aerial/Source/Views/AerialView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
// play another video
let oldPlayer = self.player
self.player = player
player.isMuted = true
player.addObserver(self, forKeyPath: "rate", options: NSKeyValueObservingOptions.new, context: nil)

self.playerLayer.player = self.player
Expand Down
Loading

0 comments on commit 73c20d0

Please sign in to comment.