yattee/Model/PlaybackState.swift

32 lines
681 B
Swift
Raw Normal View History

2021-08-22 19:13:33 +00:00
import CoreMedia
import Foundation
final class PlaybackState: ObservableObject {
2021-09-13 20:41:16 +00:00
@Published var live = false
2021-08-22 19:13:33 +00:00
@Published var stream: Stream?
@Published var time: CMTime?
2021-09-18 20:36:42 +00:00
var aspectRatio: Double? {
2021-08-22 19:13:33 +00:00
let tracks = stream?.videoAsset.tracks(withMediaType: .video)
guard tracks != nil else {
return nil
}
let size: CGSize! = tracks!.first.flatMap {
tracks!.isEmpty ? nil : $0.naturalSize.applying($0.preferredTransform)
}
guard size != nil else {
return nil
}
return size.width / size.height
}
2021-08-23 21:31:51 +00:00
func reset() {
stream = nil
time = nil
}
2021-08-22 19:13:33 +00:00
}