Skip to content

Commit 0fcd379

Browse files
committed
update
1 parent 5f9fedc commit 0fcd379

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The player's functionality is designed around a dual ⇆ interaction model:
2828

2929
- **Commands and Settings**: Through these, you instruct the player on what to do and how to do it. Settings define the environment and initial state, while commands offer real-time control. As for now, you can conveniently pass command by command; perhaps later I’ll add support for batch commands
3030

31-
- **Event Feedback**: Through event handling, the player communicates back to the application, informing it of internal changes that may need attention. Due to the nature of media players, especially in environments with dynamic content or user interactions, the flow of events can become flooded. To manage this effectively and prevent the application from being overwhelmed by the volume of incoming events, the **system collects these events every second and returns them as a batch**. Pass `Events([])` in the `settings` to enable event mechanism.
31+
- **Event Feedback**: Through event handling, the player communicates back to the application, informing it of internal changes that may need attention. Due to the nature of media players, especially in environments with dynamic content or user interactions, the flow of events can become flooded. To manage this effectively and prevent the application from being overwhelmed by the volume of incoming events, the **system collects these events every second and returns them as a batch**. Pass `Events()` in the `settings` to enable event mechanism.
3232

3333
## [Documentation(API)](https://swiftpackageindex.com/swiftuiux/swiftui-loop-videoplayer/main/documentation/swiftui_loop_videoplayer)
3434

@@ -134,7 +134,7 @@ Please note that using videos from URLs requires ensuring that you have the righ
134134
| **NotAutoPlay** | Indicates if the video should not play after initialization. Notice that if you use `command` as a control flow for the player the start command should be `.idle` | false |
135135
| **EnableVector** | Use this struct to activate settings that allow the addition of vector-based overlays via commands. If it is not passed via settings, any commands to `addVector` or `removeAllVectors` will have no effect. | Not Enabled |
136136
|**PictureInPicture**| Enable Picture-in-Picture (PiP) support. If not passed than any command like `startPiP` or `stopPiP` have no effect. Take a look the example app *Video11.swift*. It does not work on simulator. You can observe the feature only on real devices.| - |
137-
| **Events([.durationAny, .itemStatusChangedAny])** | If `Events([])` is not passed in the `settings: VideoSettings`, the event mechanism is disabled. You can specify exactly which events you want to receive (e.g., .itemStatusChangedAny) or simply pass `Events([])` to receive all available events. This setting was added to improve performance because events are emitted via @State changes, which trigger view updates. If you don’t need to observe any events, disabling them can significantly boost performance. Take a look on the implementation in the example app *Video8.swift* | - |
137+
| **Events([.durationAny, .itemStatusChangedAny])** | If `Events([])` is not passed in the `settings: VideoSettings`, the event mechanism is disabled. You can specify exactly which events you want to receive (e.g., .itemStatusChangedAny) or simply pass `Events()` to receive all available events. This setting was added to improve performance because events are emitted via @State changes, which trigger view updates. If you don’t need to observe any events, disabling them can significantly boost performance. Take a look on the implementation in the example app *Video8.swift* | - |
138138

139139
### Additional Notes on Settings
140140

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public enum Setting: Equatable, SettingsConvertible{
2121
[self]
2222
}
2323

24-
case events([PlayerEventFilter])
24+
case events([PlayerEventFilter]?)
2525

2626
///Enable vector layer to add overlay vector graphics
2727
case vector

Sources/swiftui-loop-videoplayer/settings/Events.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import Foundation
1111
public struct Events: SettingsConvertible{
1212

1313
/// Holds the specific AVLayerVideoGravity setting defining how video content should align within its layer.
14-
private let value : [PlayerEventFilter]
14+
private let value : [PlayerEventFilter]?
1515

1616
// MARK: - Life circle
1717

1818
/// Initializes a new instance
19-
public init(_ value : [PlayerEventFilter]) {
19+
public init(_ value : [PlayerEventFilter]? = nil) {
2020
self.value = value
2121
}
2222

Sources/swiftui-loop-videoplayer/utils/VideoSettings.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,18 @@ public struct VideoSettings: Equatable{
117117

118118
vector = settings.contains(.vector)
119119

120-
events = settings.fetch(by : "events", defaulted: nil)
120+
let hasEvents = settings.contains {
121+
if case .events = $0 {
122+
return true
123+
}
124+
return false
125+
}
126+
127+
if hasEvents{
128+
events = settings.fetch(by : "events", defaulted: []) ?? []
129+
}else{
130+
events = nil
131+
}
121132
}
122133
}
123134

0 commit comments

Comments
 (0)