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

View File

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

View File

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

View File

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