Skip to content

Commit 162790c

Browse files
committed
added comments
1 parent 37e9a69 commit 162790c

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,24 @@ extension LoopingPlayerProtocol {
169169
}
170170
}
171171

172+
/// Removes the observers associated with the current AVPlayerItem.
173+
///
174+
/// This function invalidates the status observer and removes the notification observer for the AVPlayerItem's end time event.
172175
func removeItemObservers(){
176+
// Invalidate and remove the status observer.
173177
statusObserver?.invalidate()
174178
statusObserver = nil
175179

180+
// Remove the observer for the AVPlayerItemDidPlayToEndTime notification.
176181
NotificationCenter.default.removeObserver(self, name: .AVPlayerItemDidPlayToEndTime, object: nil)
177182
}
178-
183+
184+
/// Adds observers to the specified AVPlayerItem.
185+
///
186+
/// This function observes changes to the status of the AVPlayerItem and registers a handler for status changes.
187+
/// - Parameter item: The AVPlayerItem to observe.
179188
func addItemObservers(for item: AVPlayerItem){
189+
// Observe the status property of the AVPlayerItem and handle changes using the provided closure.
180190
statusObserver = item.observe(\.status, options: [.new, .old]) { [weak self] item, _ in
181191
self?.handlePlayerItemStatusChange(item)
182192
print(item)
@@ -266,5 +276,4 @@ extension LoopingPlayerProtocol {
266276
removeAllVectors()
267277
}
268278
}
269-
270279
}

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

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,57 @@ import AppKit
1212
#endif
1313
import QuartzCore
1414

15+
/// A protocol that defines methods and properties for managing vector layers within a composite layer.
16+
///
17+
/// This protocol is intended to be used for managing the addition and removal of vector layers,
18+
/// which are overlaid on top of other content, such as video streams.
19+
///
1520
@available(iOS 14, macOS 11, tvOS 14, *)
1621
@MainActor
17-
public protocol LayerMakerProtocol{
18-
19-
var compositeLayer : CALayer{ get }
20-
22+
public protocol LayerMakerProtocol {
23+
24+
/// The composite layer that contains all the sublayers, including vector layers.
25+
///
26+
/// This layer acts as a container for all vector layers added through the protocol methods.
27+
var compositeLayer: CALayer { get }
28+
29+
/// The frame of the composite layer.
30+
///
31+
/// This property defines the size and position of the composite layer within its parent view.
2132
var frame: CGRect { get set }
22-
23-
var bounds : CGRect { get set }
24-
25-
func addVectorLayer(builder : any ShapeLayerBuilderProtocol, clear: Bool)
26-
33+
34+
/// The bounds of the composite layer.
35+
///
36+
/// This property defines the drawable area of the composite layer, relative to its own coordinate system.
37+
var bounds: CGRect { get set }
38+
39+
/// Adds a vector layer to the composite layer using a specified builder.
40+
///
41+
/// - Parameters:
42+
/// - builder: An instance conforming to `ShapeLayerBuilderProtocol` that constructs the vector layer.
43+
/// - clear: A Boolean value that indicates whether to clear existing vector layers before adding the new one.
44+
func addVectorLayer(builder: any ShapeLayerBuilderProtocol, clear: Bool)
45+
46+
/// Removes all vector layers from the composite layer.
2747
func removeAllVectors()
2848
}
2949

3050
extension LayerMakerProtocol{
3151

3252
@MainActor
33-
/// Sets a vector graphic operation on the video player.
53+
/// Adds a vector layer to the composite layer using a specified builder.
54+
///
3455
/// - Parameters:
35-
/// - builder: An instance conforming to `ShapeLayerBuilderProtocol` to provide the shape layer.
36-
/// - clear: A Boolean value indicating whether to clear existing vector graphics before applying the new one. Defaults to `false`.
56+
/// - builder: An instance conforming to `ShapeLayerBuilderProtocol` that constructs the vector layer.
57+
/// - clear: A Boolean value that indicates whether to clear existing vector layers before adding the new one.
3758
func addVectorLayer(builder : any ShapeLayerBuilderProtocol, clear: Bool){
3859
if clear{ removeAllVectors() }
3960
let layer = builder.build(with: (frame, bounds))
4061
compositeLayer.addSublayer(layer)
4162
}
4263

4364
@MainActor
44-
/// Clears all vector graphics from the video player.
65+
/// Removes all vector layers from the composite layer.
4566
func removeAllVectors(){
4667
compositeLayer.sublayers?.forEach { $0.removeFromSuperlayer() }
4768
}

0 commit comments

Comments
 (0)