1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Model/Player/PlayerTimeModel.swift

39 lines
1.2 KiB
Swift
Raw Normal View History

import CoreMedia
import Foundation
import SwiftUI
final class PlayerTimeModel: ObservableObject {
2022-09-01 00:54:46 +05:30
static let shared = PlayerTimeModel()
static let timePlaceholder = "--:--"
@Published var currentTime = CMTime.zero
@Published var duration = CMTime.zero
var player: PlayerModel { .shared }
2022-08-27 06:13:47 +05:30
var forceHours: Bool {
duration.seconds >= 60 * 60
}
var currentPlaybackTime: String {
if player.currentItem.isNil || duration.seconds.isZero {
return Self.timePlaceholder
}
2022-08-27 06:13:47 +05:30
return currentTime.seconds.formattedAsPlaybackTime(allowZero: true, forceHours: forceHours) ?? Self.timePlaceholder
}
var durationPlaybackTime: String {
if player.currentItem.isNil {
return Self.timePlaceholder
}
return duration.seconds.formattedAsPlaybackTime() ?? Self.timePlaceholder
}
var withoutSegmentsPlaybackTime: String {
guard let withoutSegmentsDuration = player.playerItemDurationWithoutSponsorSegments?.seconds else { return Self.timePlaceholder }
return withoutSegmentsDuration.formattedAsPlaybackTime(forceHours: forceHours) ?? Self.timePlaceholder
}
}