Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6409466

Browse files
Update fn+.swift
1 parent 89a8f58 commit 6409466

File tree

1 file changed

+20
-5
lines changed
  • Sources/swiftui-loop-videoplayer/fn

1 file changed

+20
-5
lines changed

‎Sources/swiftui-loop-videoplayer/fn/fn+.swift

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,28 @@ func mergeAssetWithSubtitles(videoAsset: AVURLAsset, subtitleAsset: AVURLAsset)
244244
/// This value must be valid for the calculation to work correctly.
245245
/// - Returns: A `CMTime` value representing the resolved seek position within the media.
246246
@MainActor
247-
func getSeekTime(for time: Double, duration: CMTime) -> CMTime? {
248-
guard duration.isNumeric && duration.value != 0 else { return nil }
247+
func getSeekTime(for time: Double, duration : CMTime) -> CMTime?{
249248

250-
let endSeconds = CMTimeGetSeconds(duration)
251-
let clampedSeconds = max(0, min(time, endSeconds))
249+
guard duration.value != 0 else{ return nil }
250+
251+
252+
let endTime = CMTimeGetSeconds(duration)
253+
let seekTime : CMTime
254+
255+
if time < 0 {
256+
// If the time is negative, seek to the start of the video
257+
seekTime = .zero
258+
} else if time >= endTime {
259+
// If the time exceeds the video duration, seek to the end of the video
260+
let endCMTime = CMTime(seconds: endTime, preferredTimescale: duration.timescale)
261+
seekTime = endCMTime
262+
} else {
263+
// Otherwise, seek to the specified time
264+
let seekCMTime = CMTime(seconds: time, preferredTimescale: duration.timescale)
265+
seekTime = seekCMTime
266+
}
252267

253-
return CMTime(seconds: clampedSeconds, preferredTimescale: duration.timescale)
268+
return seekTime
254269
}
255270

256271
/// Creates an `AVPlayerItem` with optional subtitle merging.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /