Model improvements

This commit is contained in:
Arkadiusz Fal
2022-08-31 21:24:46 +02:00
parent b220f212df
commit 0d3ccc00ce
23 changed files with 190 additions and 133 deletions

View File

@@ -79,7 +79,7 @@ final class AVPlayerBackend: PlayerBackend {
init(model: PlayerModel, controls: PlayerControlsModel?, playerTime: PlayerTimeModel?) {
self.model = model
self.controls = controls
self.playerTime = playerTime
self.playerTime = playerTime ?? PlayerTimeModel.shared
addFrequentTimeObserver()
addInfrequentTimeObserver()
@@ -582,6 +582,7 @@ final class AVPlayerBackend: PlayerBackend {
}
if player.timeControlStatus == .playing {
self.model.objectWillChange.send()
if player.rate != self.model.currentRate {
player.rate = self.model.currentRate
}

View File

@@ -129,7 +129,7 @@ final class MPVBackend: PlayerBackend {
) {
self.model = model
self.controls = controls
self.playerTime = playerTime
self.playerTime = playerTime ?? PlayerTimeModel.shared
self.networkState = networkState
clientTimer = .init(interval: .seconds(Self.timeUpdateInterval), mode: .infinite) { [weak self] _ in

View File

@@ -272,7 +272,11 @@ final class MPVClient: ObservableObject {
UIView.animate(withDuration: 0.2, animations: {
let aspectRatio = self.aspectRatio > 0 && self.aspectRatio < VideoPlayerView.defaultAspectRatio ? self.aspectRatio : VideoPlayerView.defaultAspectRatio
let height = [self.backend.model.playerSize.height, self.backend.model.playerSize.width / aspectRatio].min()!
let offsetY = self.backend.model.playingFullScreen ? ((self.backend.model.playerSize.height / 2.0) - (height / 2)) : 0
var insets = 0.0
#if os(iOS)
insets = OrientationTracker.shared.currentInterfaceOrientation.isPortrait ? SafeArea.insets.bottom : 0
#endif
let offsetY = self.backend.model.playingFullScreen ? ((self.backend.model.playerSize.height / 2.0) - ((height + insets) / 2)) : 0
self.glView?.frame = CGRect(x: 0, y: offsetY, width: roundedWidth, height: height)
}) { completion in
if completion {

View File

@@ -130,8 +130,8 @@ extension PlayerBackend {
return
}
#endif
self.playerTime.currentTime = self.currentTime ?? .zero
self.playerTime.duration = self.playerItemDuration ?? .zero
PlayerTimeModel.shared.currentTime = self.currentTime ?? .zero
PlayerTimeModel.shared.duration = self.playerItemDuration ?? .zero
completionHandler?()
}
}