1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 14:20:32 +05:30
yattee/Model/Stream.swift

48 lines
1.2 KiB
Swift
Raw Normal View History

2021-06-14 23:35:02 +05:30
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 22:05:21 +05:30
var assets: [AVURLAsset] {
[audioAsset, videoAsset]
}
var assetsLoaded: Bool {
assets.allSatisfy { $0.statusOfValue(forKey: "playable", error: nil) == .loaded }
}
2021-06-16 02:51:57 +05:30
var loadedAssets: [AVURLAsset] {
assets.filter { $0.statusOfValue(forKey: "playable", error: nil) == .loaded }
}
2021-06-15 22:05:21 +05:30
func cancelLoadingAssets() {
assets.forEach { $0.cancelLoading() }
audioAsset = AVURLAsset(url: audioAsset.url)
videoAsset = AVURLAsset(url: videoAsset.url)
}
2021-06-14 23:35:02 +05:30
static func == (lhs: Stream, rhs: Stream) -> Bool {
lhs.resolution == rhs.resolution && lhs.type == rhs.type
}
}