mirror of
https://github.com/yattee/yattee.git
synced 2025-01-09 06:17:10 +00:00
Preserve playback rate between restarts
This commit is contained in:
parent
04a5224ab0
commit
a44cce462a
@ -177,8 +177,8 @@ final class AVPlayerBackend: PlayerBackend {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setRate(_ rate: Float) {
|
func setRate(_ rate: Double) {
|
||||||
avPlayer.rate = rate
|
avPlayer.rate = Float(rate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func closeItem() {
|
func closeItem() {
|
||||||
@ -616,8 +616,8 @@ final class AVPlayerBackend: PlayerBackend {
|
|||||||
|
|
||||||
if player.timeControlStatus == .playing {
|
if player.timeControlStatus == .playing {
|
||||||
self.model.objectWillChange.send()
|
self.model.objectWillChange.send()
|
||||||
if player.rate != self.model.currentRate {
|
if player.rate != Float(self.model.currentRate) {
|
||||||
player.rate = self.model.currentRate
|
player.rate = Float(self.model.currentRate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,8 +360,8 @@ final class MPVBackend: PlayerBackend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setRate(_ rate: Float) {
|
func setRate(_ rate: Double) {
|
||||||
client?.setDoubleAsync("speed", Double(rate))
|
client?.setDoubleAsync("speed", rate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func closeItem() {
|
func closeItem() {
|
||||||
|
@ -47,7 +47,7 @@ protocol PlayerBackend {
|
|||||||
func seek(to time: CMTime, seekType: SeekType, completionHandler: ((Bool) -> Void)?)
|
func seek(to time: CMTime, seekType: SeekType, completionHandler: ((Bool) -> Void)?)
|
||||||
func seek(to seconds: Double, seekType: SeekType, completionHandler: ((Bool) -> Void)?)
|
func seek(to seconds: Double, seekType: SeekType, completionHandler: ((Bool) -> Void)?)
|
||||||
|
|
||||||
func setRate(_ rate: Float)
|
func setRate(_ rate: Double)
|
||||||
|
|
||||||
func closeItem()
|
func closeItem()
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ final class PlayerModel: ObservableObject {
|
|||||||
|
|
||||||
static var shared: PlayerModel!
|
static var shared: PlayerModel!
|
||||||
|
|
||||||
static let availableRates: [Float] = [0.5, 0.67, 0.8, 1, 1.25, 1.5, 2]
|
static let availableRates: [Double] = [0.5, 0.67, 0.8, 1, 1.25, 1.5, 2]
|
||||||
let logger = Logger(label: "stream.yattee.app")
|
let logger = Logger(label: "stream.yattee.app")
|
||||||
|
|
||||||
var avPlayerView = AppleAVPlayerView()
|
var avPlayerView = AppleAVPlayerView()
|
||||||
@ -86,7 +86,7 @@ final class PlayerModel: ObservableObject {
|
|||||||
}}
|
}}
|
||||||
@Published var aspectRatio = VideoPlayerView.defaultAspectRatio
|
@Published var aspectRatio = VideoPlayerView.defaultAspectRatio
|
||||||
@Published var stream: Stream?
|
@Published var stream: Stream?
|
||||||
@Published var currentRate: Float = 1.0 { didSet { backend.setRate(currentRate) } }
|
@Published var currentRate: Double = 1.0 { didSet { handleCurrentRateChange() } }
|
||||||
|
|
||||||
@Published var qualityProfileSelection: QualityProfile? { didSet { handleQualityProfileChange() } }
|
@Published var qualityProfileSelection: QualityProfile? { didSet { handleQualityProfileChange() } }
|
||||||
|
|
||||||
@ -162,6 +162,7 @@ final class PlayerModel: ObservableObject {
|
|||||||
@Default(.closePiPOnNavigation) var closePiPOnNavigation
|
@Default(.closePiPOnNavigation) var closePiPOnNavigation
|
||||||
@Default(.closePiPOnOpeningPlayer) var closePiPOnOpeningPlayer
|
@Default(.closePiPOnOpeningPlayer) var closePiPOnOpeningPlayer
|
||||||
@Default(.resetWatchedStatusOnPlaying) var resetWatchedStatusOnPlaying
|
@Default(.resetWatchedStatusOnPlaying) var resetWatchedStatusOnPlaying
|
||||||
|
@Default(.playerRate) var playerRate
|
||||||
|
|
||||||
#if !os(macOS)
|
#if !os(macOS)
|
||||||
@Default(.closePiPAndOpenPlayerOnEnteringForeground) var closePiPAndOpenPlayerOnEnteringForeground
|
@Default(.closePiPAndOpenPlayerOnEnteringForeground) var closePiPAndOpenPlayerOnEnteringForeground
|
||||||
@ -197,6 +198,7 @@ final class PlayerModel: ObservableObject {
|
|||||||
|
|
||||||
self.pipDelegate = pipDelegate
|
self.pipDelegate = pipDelegate
|
||||||
pipController?.delegate = pipDelegate
|
pipController?.delegate = pipDelegate
|
||||||
|
currentRate = playerRate
|
||||||
}
|
}
|
||||||
|
|
||||||
func show() {
|
func show() {
|
||||||
@ -540,6 +542,11 @@ final class PlayerModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleCurrentRateChange() {
|
||||||
|
backend.setRate(currentRate)
|
||||||
|
playerRate = currentRate
|
||||||
|
}
|
||||||
|
|
||||||
func handleQualityProfileChange() {
|
func handleQualityProfileChange() {
|
||||||
guard let profile = qualityProfile else { return }
|
guard let profile = qualityProfile else { return }
|
||||||
|
|
||||||
@ -552,7 +559,7 @@ final class PlayerModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func rateLabel(_ rate: Float) -> String {
|
func rateLabel(_ rate: Double) -> String {
|
||||||
let formatter = NumberFormatter()
|
let formatter = NumberFormatter()
|
||||||
formatter.minimumFractionDigits = 0
|
formatter.minimumFractionDigits = 0
|
||||||
formatter.maximumFractionDigits = 2
|
formatter.maximumFractionDigits = 2
|
||||||
|
@ -60,7 +60,7 @@ extension PlayerModel {
|
|||||||
|
|
||||||
private var rateMenuActions: [UIAction] {
|
private var rateMenuActions: [UIAction] {
|
||||||
PlayerModel.availableRates.map { rate in
|
PlayerModel.availableRates.map { rate in
|
||||||
let image = currentRate == Float(rate) ? UIImage(systemName: "checkmark") : nil
|
let image = currentRate == rate ? UIImage(systemName: "checkmark") : nil
|
||||||
|
|
||||||
return UIAction(title: rateLabel(rate), image: image) { _ in
|
return UIAction(title: rateLabel(rate), image: image) { _ in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
@ -87,6 +87,7 @@ extension Defaults.Keys {
|
|||||||
static let chargingCellularProfileDefault = hd1080pMPVProfile.id
|
static let chargingCellularProfileDefault = hd1080pMPVProfile.id
|
||||||
static let chargingNonCellularProfileDefault = hd1080pMPVProfile.id
|
static let chargingNonCellularProfileDefault = hd1080pMPVProfile.id
|
||||||
#endif
|
#endif
|
||||||
|
static let playerRate = Key<Double>("playerRate", default: 1.0)
|
||||||
static let qualityProfiles = Key<[QualityProfile]>("qualityProfiles", default: qualityProfilesDefault)
|
static let qualityProfiles = Key<[QualityProfile]>("qualityProfiles", default: qualityProfilesDefault)
|
||||||
static let batteryCellularProfile = Key<QualityProfile.ID>("batteryCellularProfile", default: batteryCellularProfileDefault)
|
static let batteryCellularProfile = Key<QualityProfile.ID>("batteryCellularProfile", default: batteryCellularProfileDefault)
|
||||||
static let batteryNonCellularProfile = Key<QualityProfile.ID>("batteryNonCellularProfile", default: batteryNonCellularProfileDefault)
|
static let batteryNonCellularProfile = Key<QualityProfile.ID>("batteryNonCellularProfile", default: batteryNonCellularProfileDefault)
|
||||||
|
Loading…
Reference in New Issue
Block a user