-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
VideoFormatViewController.swift
107 lines (89 loc) · 3.37 KB
/
VideoFormatViewController.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// VideoFormatViewController.swift
// Aerial
//
// Created by Guillaume Louel on 11/08/2020.
// Copyright © 2020 Guillaume Louel. All rights reserved.
//
import Cocoa
import AVKit
class VideoFormatViewController: NSViewController {
@IBOutlet var videoFormatPopup: NSPopUpButton!
@IBOutlet var previewView: AVPlayerView!
// We need to hide HDR pre-Catalina
@IBOutlet var menu1080pHDR: NSMenuItem!
@IBOutlet var menu4KHDR: NSMenuItem!
@IBOutlet var labelBelow: NSTextField!
var currentVideo: AerialVideo?
@IBOutlet var warnImage: NSImageView!
@IBOutlet var warnLabel: NSTextField!
var originalFormat: VideoFormat?
override func viewDidLoad() {
super.viewDidLoad()
// We need catalina for HDR !
if #available(OSX 10.15, *) {
} else {
menu1080pHDR.isHidden = true
menu4KHDR.isHidden = true
}
warnLabel.isHidden = true
warnImage.isHidden = true
// Only detect if we have the default basic format, don't override people's settings
if PrefsVideos.videoFormat == .v1080pH264 {
PrefsVideos.videoFormat = HardwareDetection.sharedInstance.getSuggestedFormat()
} else {
// swiftlint:disable:next line_length
labelBelow.stringValue = "Videos are usually available in multiple formats. Your current format is preselected, but you can pick another one."
originalFormat = PrefsVideos.videoFormat
}
videoFormatPopup.selectItem(at: PrefsVideos.videoFormat.rawValue)
previewView.player = AVPlayer()
previewView.showsFullScreenToggleButton = true
//previewView.controlsStyle = .none
if #available(OSX 10.10, *) {
previewView.videoGravity = .resizeAspectFill
}
getNewVideo()
setupPlayer()
}
@IBAction func moreInfoFormats(_ sender: Any) {
let workspace = NSWorkspace.shared
let url = URL(string: "https://github.com/JohnCoates/Aerial/blob/master/Documentation/HardwareDecoding.md")!
workspace.open(url)
}
@IBAction func newVideoClick(_ sender: Any) {
getNewVideo()
setupPlayer()
}
@IBAction func formatChange(_ sender: NSPopUpButton) {
if let original = originalFormat {
let candidateFormat = VideoFormat(rawValue: sender.indexOfSelectedItem)!
if candidateFormat != original {
warnLabel.isHidden = false
warnImage.isHidden = false
} else {
warnLabel.isHidden = true
warnImage.isHidden = true
}
}
PrefsVideos.videoFormat = VideoFormat(rawValue: sender.indexOfSelectedItem)!
setupPlayer()
}
func setupPlayer() {
if let player = previewView.player {
if let video = currentVideo {
player.pause()
if let onlineUrl = URL(string: (video.urls[PrefsVideos.videoFormat])!) {
let asset = AVAsset(url: onlineUrl)
let item = AVPlayerItem(asset: asset)
player.replaceCurrentItem(with: item)
player.play()
}
}
}
}
// Get a random video available in all format
func getNewVideo() {
currentVideo = VideoList.instance.videos.filter({ $0.hasHDR() == true }).shuffled().first
}
}