mirror of
https://github.com/yattee/yattee.git
synced 2024-11-14 01:58:24 +00:00
31 lines
650 B
Swift
31 lines
650 B
Swift
import CoreMedia
|
|
import Foundation
|
|
|
|
final class PlaybackState: ObservableObject {
|
|
@Published var stream: Stream?
|
|
@Published var time: CMTime?
|
|
|
|
var aspectRatio: CGFloat? {
|
|
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
|
|
}
|
|
|
|
func reset() {
|
|
stream = nil
|
|
time = nil
|
|
}
|
|
}
|