@@ -243,10 +243,16 @@ extension AbstractPlayer{
243
243
}
244
244
}
245
245
246
- /// Seeks the video to a specific time.
247
- /// This method moves the playback position to the specified time with precise accuracy.
248
- /// If the specified time is out of bounds, it will be clamped to the nearest valid time.
249
- /// - Parameter time: The target time to seek to in the video timeline.
246
+ /// Seeks the video to a specific time in the timeline.
247
+ /// This method adjusts the playback position to the specified time with precise accuracy.
248
+ /// If the target time is out of bounds (negative or beyond the duration), it will be clamped to the nearest valid time (start or end of the video).
249
+ ///
250
+ /// - Parameters:
251
+ /// - time: A `Double` value representing the target time (in seconds) to seek to in the video timeline.
252
+ /// If the value is less than 0, the playback position will be set to the start of the video.
253
+ /// If the value exceeds the video's duration, it will be set to the end.
254
+ /// - play: A `Bool` value indicating whether to start playback immediately after seeking.
255
+ /// Defaults to `false`, meaning playback will remain paused after the seek operation.
250
256
func seek( to time: Double , play: Bool = false ) {
251
257
guard let player = player, let duration = player. currentItem? . duration else {
252
258
guard let settings = currentSettings else {
@@ -274,21 +280,7 @@ extension AbstractPlayer{
274
280
return
275
281
}
276
282
277
- let endTime = CMTimeGetSeconds ( duration)
278
- let seekTime : CMTime
279
-
280
- if time < 0 {
281
- // If the time is negative, seek to the start of the video
282
- seekTime = . zero
283
- } else if time >= endTime {
284
- // If the time exceeds the video duration, seek to the end of the video
285
- let endCMTime = CMTime ( seconds: endTime, preferredTimescale: duration. timescale)
286
- seekTime = endCMTime
287
- } else {
288
- // Otherwise, seek to the specified time
289
- let seekCMTime = CMTime ( seconds: time, preferredTimescale: duration. timescale)
290
- seekTime = seekCMTime
291
- }
283
+ let seekTime = getSeekTime ( for: time, duration: duration)
292
284
293
285
player. seek ( to: seekTime) { [ weak self] value in
294
286
let currentTime = CMTimeGetSeconds ( player. currentTime ( ) )
0 commit comments