Skip to content

Commit b7e48f4

Browse files
committed
Update AbstractPlayer.swift
1 parent d10f520 commit b7e48f4

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,9 @@ extension AbstractPlayer{
206206

207207
// Check if the video is already being looped
208208
if playerLooper != nil {
209-
return // Already looped, no need to loop again
209+
return
210210
}
211211

212-
// Initialize the player looper with the current item
213212
playerLooper = AVPlayerLooper(player: player, templateItem: currentItem)
214213
}
215214

@@ -264,15 +263,10 @@ extension AbstractPlayer{
264263
/// and assigns it to the current AVPlayerItem. The video is paused during this process to ensure smooth application.
265264
/// This method is not supported on Vision OS.
266265
func applyVideoComposition() {
267-
guard let player = player, let currentItem = player.currentItem else { return }
268-
266+
guard let player = player else { return }
269267
let allFilters = combineFilters(filters, brightness, contrast)
270-
#if !os(visionOS)
271-
// Might be heavy operation need to explore
272-
let videoComposition = AVVideoComposition(asset: currentItem.asset, applyingCIFiltersWithHandler: { request in
273-
handleVideoComposition(request: request, filters: allFilters)
274-
})
275268

269+
#if !os(visionOS)
276270
// Optionally, check if the player is currently playing
277271
let wasPlaying = player.rate != 0
278272

@@ -281,8 +275,14 @@ extension AbstractPlayer{
281275
player.pause()
282276
}
283277

284-
// Applying the video composition
285-
currentItem.videoComposition = videoComposition
278+
player.items().forEach{ item in
279+
280+
let videoComposition = AVVideoComposition(asset: item.asset, applyingCIFiltersWithHandler: { request in
281+
handleVideoComposition(request: request, filters: allFilters)
282+
})
283+
284+
item.videoComposition = videoComposition
285+
}
286286

287287
if wasPlaying{
288288
player.play()

0 commit comments

Comments
 (0)