Skip to content

Commit 3a9b80b

Browse files
committed
update
1 parent 3287266 commit 3a9b80b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Sources/swiftui-loop-videoplayer/PlayerView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public struct PlayerView: UIViewRepresentable {
3939
self.videoGravity = videoGravity
4040
}
4141

42+
/// Inherited from UIViewRepresentable
4243
public func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<PlayerView>) {
4344
}
4445

@@ -47,10 +48,10 @@ public struct PlayerView: UIViewRepresentable {
4748
public func makeUIView(context: Context) -> UIView {
4849
let name = resourceName
4950
let ext = extention
50-
if let view = LoopingPlayerUIView(name, width: ext, gravity: videoGravity){
51-
return view
51+
guard let view = LoopingPlayerUIView(name, width: ext, gravity: videoGravity) else{
52+
return errorTpl()
5253
}
53-
return errorTpl()
54+
return view
5455
}
5556

5657
/// - Returns: Error view

Sources/swiftui-loop-videoplayer/view/LoopingPlayerUIView.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ class LoopingPlayerUIView: UIView {
2020
required init?(coder: NSCoder) {
2121
fatalError("init(coder:) has not been implemented")
2222
}
23-
24-
init?(_ name: String, width ext: String, gravity: AVLayerVideoGravity) {
23+
24+
/// - Parameters:
25+
/// - name: Name of the video to play
26+
/// - ext: Video extension
27+
/// - gravity: A structure that defines how a layer displays a player’s visual content within the layer’s bounds
28+
public init?(_ name: String, width ext: String, gravity: AVLayerVideoGravity) {
2529

2630
/// Load the resource
2731
guard let fileUrl = Bundle.main.url(forResource: name, withExtension: ext) else{
@@ -49,7 +53,8 @@ class LoopingPlayerUIView: UIView {
4953

5054
layer.addSublayer(playerLayer)
5155
}
52-
56+
57+
/// override point. called by layoutIfNeeded automatically. As of iOS 6.0, when constraints-based layout is used the base implementation applies the constraints-based layout, otherwise it does nothing.
5358
override func layoutSubviews() {
5459
super.layoutSubviews()
5560
playerLayer.frame = bounds

0 commit comments

Comments
 (0)