Skip to content

Commit f615c05

Browse files
committed
update
1 parent 436f764 commit f615c05

File tree

5 files changed

+7
-40
lines changed

5 files changed

+7
-40
lines changed

Sources/swiftui-loop-videoplayer/fn/fn+.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ fileprivate func extractExtension(from name: String) -> String? {
5151
/// - playerLooper: A reference to the AVPlayerLooper associated with the player. This is also passed by reference to nullify and help in cleaning up.
5252
/// - statusObserver: A reference to an observer watching the player's status changes. Passing by reference allows the function to dispose of it properly.
5353
/// - errorObserver: A reference to an observer monitoring errors from the player. It is managed in the same way as statusObserver to ensure proper cleanup.
54-
func cleanUp(player: inout AVQueuePlayer?, playerLooper: inout AVPlayerLooper?, statusObserver: inout NSKeyValueObservation?, errorObserver: inout NSKeyValueObservation?) {
54+
func cleanUp(player: inout AVQueuePlayer?, playerLooper: inout AVPlayerLooper?, errorObserver: inout NSKeyValueObservation?) {
5555
// Invalidate and remove references to observers
56-
statusObserver?.invalidate()
5756
errorObserver?.invalidate()
58-
statusObserver = nil
5957
errorObserver = nil
6058

6159
// Pause the player and release player-related resources

Sources/swiftui-loop-videoplayer/protocol/player/AbstractPlayer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ extension AbstractPlayer{
332332
guard !filters.isEmpty else { return }
333333

334334
filters = []
335+
335336
if apply{
336337
applyVideoComposition()
337338
}

Sources/swiftui-loop-videoplayer/protocol/view/LoopingPlayerProtocol.swift

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ public protocol LoopingPlayerProtocol: AbstractPlayer, LayerMakerProtocol{
3131

3232
/// The delegate to be notified about errors encountered by the player.
3333
var delegate: PlayerErrorDelegate? { get set }
34-
35-
/// An optional NSKeyValueObservation to monitor changes in the playback status of the video.
36-
/// This observer should be set up to watch for changes such as play, pause, or errors in the AVPlayerItem,
37-
/// allowing the conforming object to respond to different states of the video playback.
38-
var statusObserver: NSKeyValueObservation? { get set }
3934

4035
/// An optional NSKeyValueObservation to monitor errors encountered by the video player.
4136
/// This observer should be configured to detect and handle errors from the AVQueuePlayer,
@@ -85,22 +80,19 @@ extension LoopingPlayerProtocol {
8580
player?.pause()
8681
}
8782

88-
removeItemObservers()
83+
// Cleaning
8984
unloop()
85+
9086
removeAllFilters()
9187

92-
// Replace the current item with a new item created from the asset
88+
// Replace the current item
9389
let newItem = AVPlayerItem(asset: asset)
9490

95-
addItemObservers(for: newItem)
96-
9791
player?.replaceCurrentItem(with: newItem)
9892

9993
loop()
10094

101-
// Seek to the beginning of the item if you want to start from the start
10295
player?.seek(to: .zero, completionHandler: { _ in
103-
// Resume playing if the player was playing before
10496
if wasPlaying {
10597
self.player?.play()
10698
}
@@ -165,35 +157,11 @@ extension LoopingPlayerProtocol {
165157
/// - item: The player item to observe.
166158
/// - player: The player to observe.
167159
func setupObservers(for item: AVPlayerItem, player: AVQueuePlayer) {
168-
addItemObservers(for: item)
169160
errorObserver = player.observe(\.error, options: [.new]) { [weak self] player, _ in
170161
self?.handlePlayerError(player)
171162
}
172163
}
173-
174-
/// Removes the observers associated with the current AVPlayerItem.
175-
///
176-
/// This function invalidates the status observer and removes the notification observer for the AVPlayerItem's end time event.
177-
func removeItemObservers(){
178-
// Invalidate and remove the status observer.
179-
statusObserver?.invalidate()
180-
statusObserver = nil
181-
182-
// Remove the observer for the AVPlayerItemDidPlayToEndTime notification.
183-
NotificationCenter.default.removeObserver(self, name: .AVPlayerItemDidPlayToEndTime, object: nil)
184-
}
185164

186-
/// Adds observers to the specified AVPlayerItem.
187-
///
188-
/// This function observes changes to the status of the AVPlayerItem and registers a handler for status changes.
189-
/// - Parameter item: The AVPlayerItem to observe.
190-
func addItemObservers(for item: AVPlayerItem){
191-
// Observe the status property of the AVPlayerItem and handle changes using the provided closure.
192-
statusObserver = item.observe(\.status, options: [.new, .old]) { [weak self] item, _ in
193-
self?.handlePlayerItemStatusChange(item)
194-
print(item)
195-
}
196-
}
197165

198166
/// Responds to changes in the status of an AVPlayerItem.
199167
///

Sources/swiftui-loop-videoplayer/view/loop/player/ios/LoopingPlayerUIView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class LoopingPlayerUIView: UIView, LoopingPlayerProtocol {
7373
/// pauses the player, and clears out player-related references to assist in clean deinitialization.
7474
/// It also conditionally logs the cleanup process during debug mode.
7575
deinit {
76-
cleanUp(player: &player, playerLooper: &playerLooper, statusObserver: &statusObserver, errorObserver: &errorObserver)
76+
cleanUp(player: &player, playerLooper: &playerLooper, errorObserver: &errorObserver)
7777
}
7878
}
7979
#endif

Sources/swiftui-loop-videoplayer/view/loop/player/mac/LoopingPlayerNSView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class LoopingPlayerNSView: NSView, LoopingPlayerProtocol {
7575
/// pauses the player, and clears out player-related references to assist in clean deinitialization.
7676
/// It also conditionally logs the cleanup process during debug mode.
7777
deinit {
78-
cleanUp(player: &player, playerLooper: &playerLooper, statusObserver: &statusObserver, errorObserver: &errorObserver)
78+
cleanUp(player: &player, playerLooper: &playerLooper, errorObserver: &errorObserver)
7979
}
8080
}
8181
#endif

0 commit comments

Comments
 (0)