@@ -84,15 +84,9 @@ internal extension LoopingPlayerProtocol {
84
84
85
85
// Replace the current item
86
86
let newItem = AVPlayerItem ( asset: asset)
87
- player. replaceCurrentItem ( with : newItem )
87
+ player. insert ( newItem , after : nil )
88
88
loop ( )
89
- applyVideoComposition ( )
90
-
91
- player. seek ( to: . zero, completionHandler: { [ weak self] _ in
92
- if wasPlaying {
93
- self ? . play ( )
94
- }
95
- } )
89
+ play ( )
96
90
}
97
91
98
92
/// Sets up the player components with the specified media asset, display properties, and optional time publishing interval.
@@ -190,63 +184,6 @@ internal extension LoopingPlayerProtocol {
190
184
delegate? . didReceiveError ( . remoteVideoError( error) )
191
185
}
192
186
193
- /// Processes an asynchronous video composition request by applying a series of CIFilters.
194
- /// This function ensures each frame processed conforms to specified filter effects.
195
- ///
196
- /// - Parameters:
197
- /// - request: An AVAsynchronousCIImageFilteringRequest object representing the current video frame to be processed.
198
- /// - filters: An array of CIFilters to be applied sequentially to the video frame.
199
- ///
200
- /// The function starts by clamping the source image to ensure coordinates remain within the image bounds,
201
- /// applies each filter in the provided array, and completes by returning the modified image to the composition request.
202
- static func handleVideoComposition( request: AVAsynchronousCIImageFilteringRequest , filters: [ CIFilter ] ) {
203
- // Start with the source image, ensuring it's clamped to avoid any coordinate issues
204
- var currentImage = request. sourceImage. clampedToExtent ( )
205
-
206
- // Apply each filter in the array to the image
207
- for filter in filters {
208
- filter. setValue ( currentImage, forKey: kCIInputImageKey)
209
- if let outputImage = filter. outputImage {
210
- currentImage = outputImage. clampedToExtent ( )
211
- }
212
- }
213
- // Finish the composition request by outputting the final image
214
- request. finish ( with: currentImage, context: nil )
215
- }
216
-
217
- /// Applies the current set of filters to the video using an AVVideoComposition.
218
- /// This method combines the existing filters and brightness/contrast adjustments, creates a new video composition,
219
- /// and assigns it to the current AVPlayerItem. The video is paused during this process to ensure smooth application.
220
- /// This method is not supported on Vision OS.
221
- func applyVideoComposition( ) {
222
- guard let player = player else { return }
223
- let allFilters = combineFilters ( filters, brightness, contrast)
224
-
225
- #if !os(visionOS)
226
- // Optionally, check if the player is currently playing
227
- let wasPlaying = player. rate != 0
228
-
229
- // Pause the player if it was playing
230
- if wasPlaying {
231
- player. pause ( )
232
- }
233
-
234
- player. items ( ) . forEach { item in
235
-
236
- let videoComposition = AVVideoComposition ( asset: item. asset, applyingCIFiltersWithHandler: { request in
237
- Self . handleVideoComposition ( request: request, filters: allFilters)
238
- } )
239
-
240
- item. videoComposition = videoComposition
241
- }
242
-
243
- if wasPlaying{
244
- player. play ( )
245
- }
246
-
247
- #endif
248
- }
249
-
250
187
/// Clears all items from the player's queue.
251
188
func clearPlayerQueue( ) {
252
189
guard let items = player? . items ( ) else { return }
0 commit comments