no need for NotificationCenter

This commit is contained in:
Toni Förster 2023-12-05 00:07:36 +01:00
parent 4ca8adc4dd
commit 721a97dc41
No known key found for this signature in database
GPG Key ID: 292F3E5086C83FC7
4 changed files with 4 additions and 24 deletions

View File

@ -116,10 +116,6 @@ final class AVPlayerBackend: PlayerBackend {
#endif #endif
} }
deinit {
NotificationCenter.default.removeObserver(self, name: .getTimeUpdatesNotification, object: self.currentTime)
}
func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting) -> Stream? { func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting) -> Stream? {
let sortedByResolution = streams let sortedByResolution = streams
.filter { ($0.kind == .adaptive || $0.kind == .stream) && $0.resolution <= maxResolution.value } .filter { ($0.kind == .adaptive || $0.kind == .stream) && $0.resolution <= maxResolution.value }
@ -601,7 +597,7 @@ final class AVPlayerBackend: PlayerBackend {
self.updateControls() self.updateControls()
} }
NotificationCenter.default.post(name: .getTimeUpdatesNotification, object: self.currentTime) self.model.updateTime(self.currentTime!)
} }
} }

View File

@ -182,6 +182,7 @@ final class MPVBackend: PlayerBackend {
} }
init() { init() {
// swiftlint:disable shorthand_optional_binding
clientTimer = .init(interval: .seconds(Self.timeUpdateInterval), mode: .infinite) { [weak self] _ in clientTimer = .init(interval: .seconds(Self.timeUpdateInterval), mode: .infinite) { [weak self] _ in
guard let self = self, self.model.activeBackend == .mpv else { guard let self = self, self.model.activeBackend == .mpv else {
return return
@ -195,10 +196,7 @@ final class MPVBackend: PlayerBackend {
} }
self.updateNetworkState() self.updateNetworkState()
} }
} // swiftlint:enable shorthand_optional_binding
deinit {
NotificationCenter.default.removeObserver(self, name: .getTimeUpdatesNotification, object: self.currentTime)
} }
typealias AreInIncreasingOrder = (Stream, Stream) -> Bool typealias AreInIncreasingOrder = (Stream, Stream) -> Bool
@ -443,7 +441,7 @@ final class MPVBackend: PlayerBackend {
self.model.updateWatch(time: self.currentTime) self.model.updateWatch(time: self.currentTime)
} }
NotificationCenter.default.post(name: .getTimeUpdatesNotification, object: self.currentTime) self.model.updateTime(self.currentTime!)
} }
private func stopClientUpdates() { private func stopClientUpdates() {

View File

@ -154,7 +154,3 @@ extension PlayerBackend {
} }
} }
} }
extension Notification.Name {
static let getTimeUpdatesNotification = Notification.Name("getTimeUpdatesNotification")
}

View File

@ -1,4 +1,3 @@
import CoreMedia
import Defaults import Defaults
import Foundation import Foundation
import SDWebImageSwiftUI import SDWebImageSwiftUI
@ -486,15 +485,6 @@ struct VideoDetails: View {
.padding(.horizontal) .padding(.horizontal)
} }
} }
.onReceive(
NotificationCenter.default
.publisher(for: .getTimeUpdatesNotification)
.receive(on: DispatchQueue.main)
) { notification in
if let cmTime = notification.object as? CMTime {
player.updateTime(cmTime)
}
}
} }
} }