File tree Expand file tree Collapse file tree 1 file changed +22
-6
lines changed
Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -179,6 +179,8 @@ struct VideoControlView: View {
179179 @Binding var isPlaying : Bool
180180 @Binding var currentTime : CMTime
181181 let videoState : VideoState
182+ @State private var sliderValue : Double = 0
183+ @State private var isSeeking = false
182184
183185 var duration : Double {
184186 switch videoState {
@@ -199,21 +201,35 @@ struct VideoControlView: View {
199201 }
200202 . buttonStyle ( . plain)
201203
202- Text ( formatTime ( currentTime. seconds) )
204+ Text ( formatTime ( isSeeking ? sliderValue : currentTime. seconds) )
203205 . font ( . caption)
204206 . monospacedDigit ( )
205207
206- Slider ( value: Binding ( get: {
207- currentTime. seconds
208- } , set: { newValue in
209- currentTime = CMTime ( seconds: newValue, preferredTimescale: 600 )
210- } ) , in: 0 ... max ( duration, 0.1 ) )
208+ Slider ( value: $sliderValue, in: 0 ... max ( duration, 0.1 ) ) { editing in
209+ isSeeking = editing
210+ if !editing {
211+ currentTime = CMTime ( seconds: sliderValue, preferredTimescale: 600 )
212+ }
213+ }
211214
212215 Text ( formatTime ( duration) )
213216 . font ( . caption)
214217 . monospacedDigit ( )
215218 }
216219 }
220+ . onAppear {
221+ sliderValue = currentTime. seconds
222+ }
223+ . onChange ( of: currentTime. seconds) { _, newValue in
224+ if !isSeeking {
225+ sliderValue = newValue
226+ }
227+ }
228+ . onChange ( of: duration) { _, newValue in
229+ if sliderValue > newValue {
230+ sliderValue = newValue
231+ }
232+ }
217233 }
218234
219235 func formatTime( _ seconds: Double ) -> String {
You can’t perform that action at this time.
0 commit comments