Skip to content

Commit 44731e4

Browse files
committed
refactoring
1 parent e020179 commit 44731e4

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ class LoopingPlayerUIView: UIView, LoopingPlayerProtocol {
6464
playerLayer.backgroundColor = UIColor.clear.cgColor
6565
layer.addSublayer(playerLayer)
6666

67-
playerLooper = AVPlayerLooper(player: player, templateItem: player.items().first!)
67+
if let firstItem = player.items().first {
68+
playerLooper = AVPlayerLooper(player: player, templateItem: firstItem)
69+
}
6870
player.play()
6971
}
7072

Sources/swiftui-loop-videoplayer/view/loop/mac/LoopingPlayerNSView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ class LoopingPlayerNSView: NSView, LoopingPlayerProtocol {
6868
layer?.addSublayer(playerLayer)
6969
wantsLayer = true
7070

71-
playerLooper = AVPlayerLooper(player: player, templateItem: player.items().first!)
71+
if let firstItem = player.items().first {
72+
playerLooper = AVPlayerLooper(player: player, templateItem: firstItem)
73+
}
7274
player.play()
7375
}
7476

0 commit comments

Comments
 (0)