@@ -98,7 +98,11 @@ public protocol AbstractPlayer: AnyObject {
98
98
/// Sets the playback command for the video player.
99
99
func setCommand( _ value: PlaybackCommand )
100
100
101
+ /// Applies the current set of filters to the video using an AVVideoComposition.
101
102
func applyVideoComposition( )
103
+
104
+ /// Updates the current playback asset, settings, and initializes playback or a specific action when the asset is ready.
105
+ func update( asset: AVURLAsset , loop: Bool , autoPlay: Bool , callback: ( ( ) -> Void ) ? )
102
106
}
103
107
104
108
extension AbstractPlayer {
@@ -138,66 +142,6 @@ extension AbstractPlayer{
138
142
func pause( ) {
139
143
player? . pause ( )
140
144
}
141
-
142
- /// Clears all items from the player's queue.
143
- func clearPlayerQueue( ) {
144
- guard let items = player? . items ( ) else { return }
145
- for item in items {
146
- player? . remove ( item)
147
- }
148
- }
149
-
150
- /// Updates the current playback asset, settings, and initializes playback or a specific action when the asset is ready.
151
- ///
152
- /// This method sets a new asset to be played, optionally loops it, and can automatically start playback.
153
- /// If provided, a callback is executed when the asset is ready to play.
154
- ///
155
- /// - Parameters:
156
- /// - asset: The AVURLAsset to be loaded into the player.
157
- /// - loop: A Boolean value indicating whether the video should loop.
158
- /// - autoPlay: A Boolean value indicating whether playback should start automatically. Default is true.
159
- /// - callback: An optional closure to be called when the asset is ready to play.
160
- func update( asset: AVURLAsset , loop: Bool , autoPlay: Bool = true , callback: ( ( ) -> Void ) ? = nil ) {
161
-
162
- guard let player = player else { return }
163
-
164
- let wasPlaying = player. rate != 0
165
-
166
- if wasPlaying {
167
- pause ( )
168
- }
169
-
170
- if !player. items ( ) . isEmpty {
171
- // Cleaning
172
- unloop ( )
173
- clearPlayerQueue ( )
174
- removeAllFilters ( )
175
- }
176
-
177
- let newItem = AVPlayerItem ( asset: asset)
178
- player. insert ( newItem, after: nil )
179
-
180
- if loop {
181
- self . loop ( )
182
- }
183
-
184
- if let statusObserver{
185
- statusObserver. invalidate ( )
186
- }
187
-
188
- if let callback{
189
- statusObserver = newItem. observe ( \. status, options: [ . new, . old] ) { [ weak self] item, change in
190
- guard item. status == . readyToPlay else { return }
191
- callback ( )
192
- self ? . statusObserver? . invalidate ( )
193
- self ? . statusObserver = nil
194
- }
195
- }
196
-
197
- if autoPlay{
198
- player. play ( )
199
- }
200
- }
201
145
202
146
/// Seeks the video to a specific time.
203
147
/// This method moves the playback position to the specified time with precise accuracy.
0 commit comments