File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed
Sources/swiftui-loop-videoplayer/protocol/view Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -72,27 +72,28 @@ extension LoopingPlayerProtocol {
72
72
/// - Parameters:
73
73
/// - asset: The AVURLAsset to load into the player.
74
74
func update( asset: AVURLAsset ) {
75
- // Optionally, check if the player is currently playing
76
- let wasPlaying = player? . rate != 0
77
75
78
- // Pause the player if it was playing
76
+ guard let player = player else { return }
77
+
78
+ let wasPlaying = player. rate != 0
79
+
79
80
if wasPlaying {
80
- player? . pause ( )
81
+ player. pause ( )
81
82
}
82
83
83
84
// Cleaning
84
85
unloop ( )
85
-
86
+ while player. items ( ) . count > 0 {
87
+ player. advanceToNextItem ( )
88
+ }
86
89
removeAllFilters ( )
87
90
88
91
// Replace the current item
89
92
let newItem = AVPlayerItem ( asset: asset)
90
-
91
- player? . replaceCurrentItem ( with: newItem)
92
-
93
+ player. replaceCurrentItem ( with: newItem)
93
94
loop ( )
94
95
95
- player? . seek ( to: . zero, completionHandler: { _ in
96
+ player. seek ( to: . zero, completionHandler: { _ in
96
97
if wasPlaying {
97
98
self . player? . play ( )
98
99
}
You can’t perform that action at this time.
0 commit comments