@@ -51,7 +51,7 @@ public protocol LoopingPlayerProtocol: AbstractPlayer, LayerMakerProtocol{
51
51
/// - Parameters:
52
52
/// - item: The AVPlayerItem to observe for status changes.
53
53
/// - player: The AVQueuePlayer to observe for errors.
54
- func setupObservers( for item : AVPlayerItem , player: AVQueuePlayer )
54
+ func setupObservers( for player: AVQueuePlayer )
55
55
56
56
/// Responds to errors reported by the AVQueuePlayer.
57
57
///
@@ -61,34 +61,6 @@ public protocol LoopingPlayerProtocol: AbstractPlayer, LayerMakerProtocol{
61
61
62
62
internal extension LoopingPlayerProtocol {
63
63
64
- /// Updates the player to play a new asset and handles the playback state.
65
- ///
66
- /// - Parameters:
67
- /// - asset: The AVURLAsset to load into the player.
68
- func update( asset: AVURLAsset , loop : Bool ) {
69
-
70
- guard let player = player else { return }
71
-
72
- let wasPlaying = player. rate != 0
73
-
74
- if wasPlaying {
75
- pause ( )
76
- }
77
-
78
- // Cleaning
79
- unloop ( )
80
- clearPlayerQueue ( )
81
- removeAllFilters ( )
82
-
83
- // Replace the current item
84
- let newItem = AVPlayerItem ( asset: asset)
85
- player. insert ( newItem, after: nil )
86
- if loop{
87
- self . loop ( )
88
- }
89
- play ( )
90
- }
91
-
92
64
/// Sets up the player components with the specified media asset, display properties, and optional time publishing interval.
93
65
///
94
66
/// - Parameters:
@@ -101,14 +73,15 @@ internal extension LoopingPlayerProtocol {
101
73
timePublishing: CMTime ? ,
102
74
loop: Bool
103
75
) {
104
- let item = AVPlayerItem ( asset: asset)
105
76
106
- let player = AVQueuePlayer ( items: [ item ] )
77
+ let player = AVQueuePlayer ( items: [ ] )
107
78
self . player = player
108
79
80
+ update ( asset: asset, loop: loop)
81
+
109
82
configurePlayer ( player, gravity: gravity, timePublishing: timePublishing, loop: loop)
110
83
111
- setupObservers ( for: item , player : player)
84
+ setupObservers ( for: player)
112
85
}
113
86
114
87
/// Configures the provided AVQueuePlayer with specific properties for video playback.
@@ -140,31 +113,21 @@ internal extension LoopingPlayerProtocol {
140
113
#endif
141
114
compositeLayer. frame = CGRect ( x: 0 , y: 0 , width: bounds. width, height: bounds. height)
142
115
143
- if loop{
144
- self . loop ( )
145
- }
146
-
147
- if !filters. isEmpty{ // have an idea for the feature
148
- applyVideoComposition ( )
149
- }
150
-
151
116
if let timePublishing{
152
117
timeObserverToken = player. addPeriodicTimeObserver ( forInterval: timePublishing, queue: . main) { [ weak self] time in
153
118
guard let self = self else { return }
154
119
155
120
self . delegate? . didPassedTime ( seconds: time. seconds)
156
121
}
157
122
}
158
-
159
- player. play ( )
160
123
}
161
124
162
125
/// Sets up observers on the player item and the player to track their status and error states.
163
126
///
164
127
/// - Parameters:
165
128
/// - item: The player item to observe.
166
129
/// - player: The player to observe.
167
- func setupObservers( for item : AVPlayerItem , player: AVQueuePlayer ) {
130
+ func setupObservers( for player: AVQueuePlayer ) {
168
131
errorObserver = player. observe ( \. error, options: [ . new] ) { [ weak self] player, _ in
169
132
self ? . handlePlayerError ( player)
170
133
}
@@ -190,13 +153,7 @@ internal extension LoopingPlayerProtocol {
190
153
delegate? . didReceiveError ( . remoteVideoError( error) )
191
154
}
192
155
193
- /// Clears all items from the player's queue.
194
- func clearPlayerQueue( ) {
195
- guard let items = player? . items ( ) else { return }
196
- for item in items {
197
- player? . remove ( item)
198
- }
199
- }
156
+
200
157
201
158
/// Sets the playback command for the video player.
202
159
/// - Parameter value: The `PlaybackCommand` to set. This can be one of the following:
0 commit comments