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

51 lines
1.5 KiB
Swift
Raw Normal View History

import Foundation
final class NetworkStateModel: ObservableObject {
2022-09-02 04:35:31 +05:30
static var shared = NetworkStateModel()
@Published var pausedForCache = false
@Published var cacheDuration = 0.0
@Published var bufferingState = 0.0
2022-09-02 04:35:31 +05:30
private var player: PlayerModel! { .shared }
private let controlsOverlayModel = ControlOverlaysModel.shared
var osdVisible: Bool {
2022-09-28 19:57:01 +05:30
guard let player else { return false }
2022-09-02 18:46:05 +05:30
return player.isPlaying && ((player.activeBackend == .mpv && pausedForCache) || player.isSeeking) && bufferingState < 100.0
2022-09-02 04:35:31 +05:30
}
var fullStateText: String? {
2022-09-28 19:57:01 +05:30
guard let bufferingStateText,
let cacheDurationText
else {
return nil
}
return "\(bufferingStateText) (\(cacheDurationText))"
}
var bufferingStateText: String? {
guard detailsAvailable && player.hasStarted else { return nil }
return String(format: "%.0f%%", bufferingState)
}
var cacheDurationText: String? {
guard detailsAvailable else { return nil }
return String(format: "%.2fs", cacheDuration)
}
var detailsAvailable: Bool {
2022-09-28 19:57:01 +05:30
guard let player else { return false }
return player.activeBackend.supportsNetworkStateBufferingDetails
}
var needsUpdates: Bool {
2022-09-28 19:57:01 +05:30
if let player {
2022-09-02 04:35:31 +05:30
return !player.currentItem.isNil && (pausedForCache || player.isSeeking || player.isLoadingVideo || controlsOverlayModel.presenting)
}
2022-08-19 04:10:46 +05:30
return false
}
}