Skip to content

Commit 0429ccb

Browse files
committed
update
1 parent af17c71 commit 0429ccb

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ extension AbstractPlayer{
277277
/// This method combines the existing filters and brightness/contrast adjustments, creates a new video composition,
278278
/// and assigns it to the current AVPlayerItem. The video is paused during this process to ensure smooth application.
279279
/// This method is not supported on Vision OS.
280-
private func applyVideoComposition() {
280+
func applyVideoComposition() {
281281
guard let player = player, let currentItem = player.currentItem else { return }
282282

283283
let allFilters = combineFilters

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ extension LoopingPlayerProtocol {
9696
player?.pause()
9797
}
9898

99-
removeStatusObserver()
99+
removeItemObservers()
100100
unloop()
101101
removeAllFilters()
102102

103103
// Replace the current item with a new item created from the asset
104104
let newItem = AVPlayerItem(asset: asset)
105105

106-
addStatusObserver(for: newItem)
106+
addItemObservers(for: newItem)
107107

108108
player?.replaceCurrentItem(with: newItem)
109109

@@ -171,20 +171,23 @@ extension LoopingPlayerProtocol {
171171
/// - item: The player item to observe.
172172
/// - player: The player to observe.
173173
func setupObservers(for item: AVPlayerItem, player: AVQueuePlayer) {
174-
addStatusObserver(for: item)
174+
addItemObservers(for: item)
175175
errorObserver = player.observe(\.error, options: [.new]) { [weak self] player, _ in
176176
self?.handlePlayerError(player)
177177
}
178178
}
179179

180-
func removeStatusObserver(){
180+
func removeItemObservers(){
181181
statusObserver?.invalidate()
182182
statusObserver = nil
183+
184+
NotificationCenter.default.removeObserver(self, name: .AVPlayerItemDidPlayToEndTime, object: nil)
183185
}
184186

185-
func addStatusObserver(for item: AVPlayerItem){
186-
statusObserver = item.observe(\.status, options: [.new]) { [weak self] item, _ in
187+
func addItemObservers(for item: AVPlayerItem){
188+
statusObserver = item.observe(\.status, options: [.new, .old]) { [weak self] item, _ in
187189
self?.handlePlayerItemStatusChange(item)
190+
print(item)
188191
}
189192
}
190193

0 commit comments

Comments
 (0)