Fix issue with AVPlayer rate restore

This commit is contained in:
Arkadiusz Fal 2023-06-08 12:22:34 +02:00
parent d95bcc4065
commit f78545baf9
2 changed files with 11 additions and 2 deletions

View File

@ -160,7 +160,7 @@ final class AVPlayerBackend: PlayerBackend {
return
}
avPlayer.playImmediately(atRate: Float(model.currentRate))
avPlayer.play()
model.objectWillChange.send()
}
@ -643,7 +643,12 @@ final class AVPlayerBackend: PlayerBackend {
if player.timeControlStatus == .playing {
self.model.objectWillChange.send()
if player.rate != Float(self.model.currentRate) {
if let rate = self.model.rateToRestore, player.rate != rate {
player.rate = rate
self.model.rateToRestore = nil
}
if player.rate > 0, player.rate != Float(self.model.currentRate) {
if self.model.avPlayerUsesSystemControls {
self.model.currentRate = Double(player.rate)
} else {

View File

@ -183,6 +183,7 @@ final class PlayerModel: ObservableObject {
var onPresentPlayer = [() -> Void]()
var onPlayStream = [(Stream) -> Void]()
var rateToRestore: Float?
private var remoteCommandCenterConfigured = false
init() {
@ -542,6 +543,9 @@ final class PlayerModel: ObservableObject {
if !self.backend.canPlayAtRate(currentRate) {
currentRate = self.backend.suggestedPlaybackRates.last { $0 < currentRate } ?? 1.0
}
self.rateToRestore = Float(currentRate)
self.backend.didChangeTo()
if wasPlaying {