yattee/Model/Stream.swift

46 lines
1.1 KiB
Swift
Raw Normal View History

2021-06-14 18:05:02 +00:00
import AVFoundation
import Foundation
// swiftlint:disable:next final_class
class Stream: Equatable {
var audioAsset: AVURLAsset
var videoAsset: AVURLAsset
var resolution: StreamResolution
var type: StreamType
var encoding: String
init(audioAsset: AVURLAsset, videoAsset: AVURLAsset, resolution: StreamResolution, type: StreamType, encoding: String) {
self.audioAsset = audioAsset
self.videoAsset = videoAsset
self.resolution = resolution
self.type = type
self.encoding = encoding
}
var description: String {
"\(resolution.height)p"
}
2021-06-15 16:35:21 +00:00
var assets: [AVURLAsset] {
[audioAsset, videoAsset]
}
var assetsLoaded: Bool {
assets.allSatisfy { $0.statusOfValue(forKey: "playable", error: nil) == .loaded }
}
2021-06-15 21:21:57 +00:00
var loadedAssets: [AVURLAsset] {
assets.filter { $0.statusOfValue(forKey: "playable", error: nil) == .loaded }
}
2021-06-15 16:35:21 +00:00
func cancelLoadingAssets() {
assets.forEach { $0.cancelLoading() }
}
2021-06-14 18:05:02 +00:00
static func == (lhs: Stream, rhs: Stream) -> Bool {
lhs.resolution == rhs.resolution && lhs.type == rhs.type
}
}