mirror of
https://github.com/yattee/yattee.git
synced 2025-10-10 17:38:15 +00:00
Player controls UI changes
WIP on controls Chapters working Add previews variable Add lists ids WIP
This commit is contained in:
50
Model/Player/PlayerTimeModel.swift
Normal file
50
Model/Player/PlayerTimeModel.swift
Normal file
@@ -0,0 +1,50 @@
|
||||
import CoreMedia
|
||||
import Foundation
|
||||
|
||||
final class PlayerTimeModel: ObservableObject {
|
||||
static let timePlaceholder = "--:--"
|
||||
|
||||
@Published var currentTime = CMTime.zero
|
||||
@Published var duration = CMTime.zero
|
||||
|
||||
var player: PlayerModel?
|
||||
|
||||
var currentPlaybackTime: String {
|
||||
if player?.currentItem.isNil ?? true || duration.seconds.isZero {
|
||||
return Self.timePlaceholder
|
||||
}
|
||||
|
||||
return currentTime.seconds.formattedAsPlaybackTime(allowZero: true) ?? Self.timePlaceholder
|
||||
}
|
||||
|
||||
var durationPlaybackTime: String {
|
||||
if player?.currentItem.isNil ?? true {
|
||||
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() ?? Self.timePlaceholder
|
||||
}
|
||||
|
||||
var durationAndWithoutSegmentsPlaybackTime: String {
|
||||
var durationAndWithoutSegmentsPlaybackTime = "\(durationPlaybackTime)"
|
||||
|
||||
if withoutSegmentsPlaybackTime != durationPlaybackTime {
|
||||
durationAndWithoutSegmentsPlaybackTime += " (\(withoutSegmentsPlaybackTime))"
|
||||
}
|
||||
|
||||
return durationAndWithoutSegmentsPlaybackTime
|
||||
}
|
||||
|
||||
func reset() {
|
||||
currentTime = .zero
|
||||
duration = .zero
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user