Minor performance improvements

This commit is contained in:
Arkadiusz Fal 2022-08-14 18:53:03 +02:00
parent c51b9dd8e8
commit 9a958113c4
4 changed files with 19 additions and 8 deletions

View File

@ -327,9 +327,13 @@ final class MPVBackend: PlayerBackend {
func closePiP(wasPlaying _: Bool) {}
func updateControls() {
guard model.presentingPlayer else {
self.logger.info("updating controls")
guard model.presentingPlayer, !model.controls.presentingOverlays else {
self.logger.info("ignored controls update")
return
}
DispatchQueue.main.async { [weak self] in
guard let self = self else {
return
@ -341,6 +345,10 @@ final class MPVBackend: PlayerBackend {
}
func startControlsUpdates() {
guard model.presentingPlayer, !model.controls.presentingOverlays else {
self.logger.info("ignored controls update start")
return
}
self.logger.info("starting controls updates")
controlsUpdates = true
}

View File

@ -10,7 +10,7 @@ final class PlayerControlsModel: ObservableObject {
@Published var presentingControls = false { didSet { handlePresentationChange() } }
@Published var presentingControlsOverlay = false { didSet { handleSettingsOverlayPresentationChange() } }
@Published var presentingDetailsOverlay = false { didSet { handleDetailsOverlayPresentationChange() } }
@Published var timer: Timer?
var timer: Timer?
#if os(tvOS)
var reporter = PassthroughSubject<String, Never>()

View File

@ -45,6 +45,9 @@ final class PlayerModel: ObservableObject {
var avPlayerBackend: AVPlayerBackend!
var mpvBackend: MPVBackend!
#if !os(macOS)
var mpvController = MPVViewController()
#endif
var backends: [PlayerBackend] {
[avPlayerBackend, mpvBackend]
@ -190,6 +193,11 @@ final class PlayerModel: ObservableObject {
networkState: networkState
)
#if !os(macOS)
mpvBackend.controller = mpvController
mpvBackend.client = mpvController.client
#endif
Defaults[.activeBackend] = .mpv
playbackMode = Defaults[.playbackMode]
}

View File

@ -2,15 +2,10 @@ import SwiftUI
#if !os(macOS)
struct MPVPlayerView: UIViewControllerRepresentable {
@State private var controller = MPVViewController()
@EnvironmentObject<PlayerModel> private var player
func makeUIViewController(context _: Context) -> some UIViewController {
player.mpvBackend.controller = controller
player.mpvBackend.client = controller.client
return controller
player.mpvController
}
func updateUIViewController(_: UIViewControllerType, context _: Context) {}