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 1dc6e54

Browse files
Revert "Update fn+.swift"
This reverts commit 6409466.
1 parent 6409466 commit 1dc6e54

File tree

1 file changed

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

1 file changed

+5
-20
lines changed

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -244,28 +244,13 @@ 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?{
247+
func getSeekTime(for time: Double, duration: CMTime) -> CMTime? {
248+
guard duration.isNumeric && duration.value != 0 else { return nil }
248249

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-
}
250+
let endSeconds = CMTimeGetSeconds(duration)
251+
let clampedSeconds = max(0, min(time, endSeconds))
267252

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

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

0 commit comments

Comments
(0)

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