@@ -31,11 +31,6 @@ public protocol LoopingPlayerProtocol: AbstractPlayer, LayerMakerProtocol{
31
31
32
32
/// The delegate to be notified about errors encountered by the player.
33
33
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 }
39
34
40
35
/// An optional NSKeyValueObservation to monitor errors encountered by the video player.
41
36
/// This observer should be configured to detect and handle errors from the AVQueuePlayer,
@@ -85,22 +80,19 @@ extension LoopingPlayerProtocol {
85
80
player? . pause ( )
86
81
}
87
82
88
- removeItemObservers ( )
83
+ // Cleaning
89
84
unloop ( )
85
+
90
86
removeAllFilters ( )
91
87
92
- // Replace the current item with a new item created from the asset
88
+ // Replace the current item
93
89
let newItem = AVPlayerItem ( asset: asset)
94
90
95
- addItemObservers ( for: newItem)
96
-
97
91
player? . replaceCurrentItem ( with: newItem)
98
92
99
93
loop ( )
100
94
101
- // Seek to the beginning of the item if you want to start from the start
102
95
player? . seek ( to: . zero, completionHandler: { _ in
103
- // Resume playing if the player was playing before
104
96
if wasPlaying {
105
97
self . player? . play ( )
106
98
}
@@ -165,35 +157,11 @@ extension LoopingPlayerProtocol {
165
157
/// - item: The player item to observe.
166
158
/// - player: The player to observe.
167
159
func setupObservers( for item: AVPlayerItem , player: AVQueuePlayer ) {
168
- addItemObservers ( for: item)
169
160
errorObserver = player. observe ( \. error, options: [ . new] ) { [ weak self] player, _ in
170
161
self ? . handlePlayerError ( player)
171
162
}
172
163
}
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
- }
185
164
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
- }
197
165
198
166
/// Responds to changes in the status of an AVPlayerItem.
199
167
///
0 commit comments