Skip to content

Commit e7e6f6c

Browse files
committed
update
1 parent cc296d4 commit e7e6f6c

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

Sources/swiftui-loop-videoplayer/enum/PlaybackCommand.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ public enum PlaybackCommand: Equatable {
5555
case contrast(Float)
5656

5757
/// Command to apply a specific Core Image filter to the video.
58-
/// - Parameter filter: A `CIFilter` object representing the filter to be applied.
59-
/// This filter is added to the current stack of filters, allowing for multiple filters to be combined and applied sequentially.
60-
case filter(CIFilter)
58+
/// - Parameters:
59+
/// - filter: A `CIFilter` object representing the filter to be applied.
60+
/// - clear: A Boolean value indicating whether to clear the existing filter stack before applying this filter.
61+
/// This filter is added to the current stack of filters, allowing for multiple filters to be combined and applied sequentially, unless `clear` is true.
62+
case filter(CIFilter, clear: Bool = false)
6163

6264
/// Command to remove all applied filters from the video playback.
6365
case removeAllFilters
@@ -94,8 +96,8 @@ public enum PlaybackCommand: Equatable {
9496
case (.audioTrack(let lhsCode), .audioTrack(let rhsCode)):
9597
return lhsCode == rhsCode
9698

97-
case (.filter(let lhs), .filter(let rhs)):
98-
return lhs == rhs
99+
case (.filter(let lhsFilter, let lhsClear), .filter(let rhsFilter, let rhsClear)):
100+
return lhsFilter == rhsFilter && lhsClear == rhsClear
99101
default:
100102
return false
101103
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ public protocol AbstractPlayer: AnyObject {
7272
func adjustContrast(to contrast: Float)
7373

7474
/// Applies a Core Image filter to the video player's content.
75-
func applyFilter(_ value: CIFilter)
75+
func applyFilter(_ value: CIFilter, _ clear : Bool)
7676

7777
/// Removes all filters from the video playback.
78-
func removeAllFilters()
78+
func removeAllFilters(apply : Bool)
7979

8080
/// Selects an audio track for the video playback.
8181
/// - Parameter languageCode: The language code (e.g., "en" for English) of the desired audio track.
@@ -244,7 +244,10 @@ extension AbstractPlayer{
244244
/// Applies a Core Image filter to the video playback.
245245
/// This function adds the provided filter to the stack of existing filters and updates the video composition accordingly.
246246
/// - Parameter value: A `CIFilter` object representing the filter to be applied to the video playback.
247-
func applyFilter(_ value: CIFilter) {
247+
func applyFilter(_ value: CIFilter, _ clear : Bool) {
248+
if clear{
249+
removeAllFilters(apply: false)
250+
}
248251
appendFilter(value) // Appends the provided filter to the current stack.
249252
applyVideoComposition() // Updates the video composition to include the new filter.
250253
}
@@ -303,9 +306,11 @@ extension AbstractPlayer{
303306
}
304307

305308
/// Removes all filters from the video playback.
306-
func removeAllFilters() {
309+
func removeAllFilters(apply : Bool = true) {
307310
filters = []
308-
applyVideoComposition()
311+
if apply{
312+
applyVideoComposition()
313+
}
309314
}
310315

311316
/// Selects an audio track for the video playback.
@@ -378,8 +383,8 @@ extension AbstractPlayer{
378383
adjustBrightness(to: brightness)
379384
case .contrast(let contrast):
380385
adjustContrast(to: contrast)
381-
case .filter(let value):
382-
applyFilter(value)
386+
case .filter(let value, let clear):
387+
applyFilter(value, clear)
383388
case .removeAllFilters:
384389
removeAllFilters()
385390
case .audioTrack(let languageCode):

0 commit comments

Comments
 (0)