From 721a97dc41aace5ac00c32351a14bb3a0b9ffe45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20F=C3=B6rster?= Date: Tue, 5 Dec 2023 00:07:36 +0100 Subject: [PATCH] no need for NotificationCenter --- Model/Player/Backends/AVPlayerBackend.swift | 6 +----- Model/Player/Backends/MPVBackend.swift | 8 +++----- Model/Player/Backends/PlayerBackend.swift | 4 ---- Shared/Player/Video Details/VideoDetails.swift | 10 ---------- 4 files changed, 4 insertions(+), 24 deletions(-) diff --git a/Model/Player/Backends/AVPlayerBackend.swift b/Model/Player/Backends/AVPlayerBackend.swift index 3ffbbb6f..7e71208f 100644 --- a/Model/Player/Backends/AVPlayerBackend.swift +++ b/Model/Player/Backends/AVPlayerBackend.swift @@ -116,10 +116,6 @@ 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 } @@ -601,7 +597,7 @@ final class AVPlayerBackend: PlayerBackend { self.updateControls() } - NotificationCenter.default.post(name: .getTimeUpdatesNotification, object: self.currentTime) + self.model.updateTime(self.currentTime!) } } diff --git a/Model/Player/Backends/MPVBackend.swift b/Model/Player/Backends/MPVBackend.swift index 5de59b13..c8457946 100644 --- a/Model/Player/Backends/MPVBackend.swift +++ b/Model/Player/Backends/MPVBackend.swift @@ -182,6 +182,7 @@ final class MPVBackend: PlayerBackend { } init() { + // swiftlint:disable shorthand_optional_binding clientTimer = .init(interval: .seconds(Self.timeUpdateInterval), mode: .infinite) { [weak self] _ in guard let self = self, self.model.activeBackend == .mpv else { return @@ -195,10 +196,7 @@ final class MPVBackend: PlayerBackend { } self.updateNetworkState() } - } - - deinit { - NotificationCenter.default.removeObserver(self, name: .getTimeUpdatesNotification, object: self.currentTime) + // swiftlint:enable shorthand_optional_binding } typealias AreInIncreasingOrder = (Stream, Stream) -> Bool @@ -443,7 +441,7 @@ final class MPVBackend: PlayerBackend { self.model.updateWatch(time: self.currentTime) } - NotificationCenter.default.post(name: .getTimeUpdatesNotification, object: self.currentTime) + self.model.updateTime(self.currentTime!) } private func stopClientUpdates() { diff --git a/Model/Player/Backends/PlayerBackend.swift b/Model/Player/Backends/PlayerBackend.swift index 45348a0b..3b09e957 100644 --- a/Model/Player/Backends/PlayerBackend.swift +++ b/Model/Player/Backends/PlayerBackend.swift @@ -154,7 +154,3 @@ extension PlayerBackend { } } } - -extension Notification.Name { - static let getTimeUpdatesNotification = Notification.Name("getTimeUpdatesNotification") -} diff --git a/Shared/Player/Video Details/VideoDetails.swift b/Shared/Player/Video Details/VideoDetails.swift index 7432dc40..1da9b6d8 100644 --- a/Shared/Player/Video Details/VideoDetails.swift +++ b/Shared/Player/Video Details/VideoDetails.swift @@ -1,4 +1,3 @@ -import CoreMedia import Defaults import Foundation import SDWebImageSwiftUI @@ -486,15 +485,6 @@ struct VideoDetails: View { .padding(.horizontal) } } - .onReceive( - NotificationCenter.default - .publisher(for: .getTimeUpdatesNotification) - .receive(on: DispatchQueue.main) - ) { notification in - if let cmTime = notification.object as? CMTime { - player.updateTime(cmTime) - } - } } }