make time updates work for .mpv and .avp

- time update notifications work for both backends
- only init mpv timers when mpv is the active backend
- move notification extension to playerbackend
This commit is contained in:
Toni Förster 2023-12-04 14:47:26 +01:00
parent 600b8d198b
commit 0d9c27319d
No known key found for this signature in database
GPG Key ID: 292F3E5086C83FC7
3 changed files with 18 additions and 6 deletions

View File

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

View File

@ -183,11 +183,17 @@ final class MPVBackend: PlayerBackend {
init() {
clientTimer = .init(interval: .seconds(Self.timeUpdateInterval), mode: .infinite) { [weak self] _ in
self?.getTimeUpdates()
guard let self = self, self.model.activeBackend == .mpv else {
return
}
self.getTimeUpdates()
}
networkStateTimer = .init(interval: .seconds(Self.networkStateUpdateInterval), mode: .infinite) { [weak self] _ in
self?.updateNetworkState()
guard let self = self, self.model.activeBackend == .mpv else {
return
}
self.updateNetworkState()
}
}
@ -624,7 +630,3 @@ final class MPVBackend: PlayerBackend {
}
}
}
extension Notification.Name {
static let getTimeUpdatesNotification = Notification.Name("getTimeUpdatesNotification")
}

View File

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