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 bfdbb57

Browse files
Revert "update"
This reverts commit 89a8f58.
1 parent 1dc6e54 commit bfdbb57

File tree

5 files changed

+26
-19
lines changed

5 files changed

+26
-19
lines changed

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,27 @@ func mergeAssetWithSubtitles(videoAsset: AVURLAsset, subtitleAsset: AVURLAsset)
243243
/// - duration: A `CMTime` value representing the total duration of the media.
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.
246-
@MainActor
247-
func getSeekTime(for time: Double, duration: CMTime) -> CMTime? {
248-
guard duration.isNumeric && duration.value != 0 else { return nil }
246+
func getSeekTime(for time: Double, duration : CMTime) -> CMTime?{
249247

250-
let endSeconds = CMTimeGetSeconds(duration)
251-
let clampedSeconds = max(0, min(time, endSeconds))
248+
guard duration.value != 0 else{ return nil }
252249

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

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

‎Sources/swiftui-loop-videoplayer/protocol/player/AbstractPlayer.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ public protocol AbstractPlayer: AnyObject {
137137
func update(settings: VideoSettings)
138138
}
139139

140-
@MainActor
141-
public extension AbstractPlayer{
140+
extension AbstractPlayer{
142141

143142
/// Retrieves the current item being played.
144143
///

‎Sources/swiftui-loop-videoplayer/protocol/player/ExtPlayerProtocol.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public protocol ExtPlayerProtocol: AbstractPlayer, LayerMakerProtocol{
7171
func onError(_ error : VPErrors)
7272
}
7373

74-
@MainActor
7574
internal extension ExtPlayerProtocol {
7675

7776
/// Initializes a new player view with a video asset and custom settings.
@@ -134,13 +133,11 @@ internal extension ExtPlayerProtocol {
134133
/// - player: The `AVQueuePlayer` instance to which the time observer will be added.
135134
/// - settings: A `VideoSettings` object containing the time publishing interval and related configuration.
136135
func configureTimePublishing(_ player: AVQueuePlayer, _ settings: VideoSettings) {
137-
if let timePublishing = settings.timePublishing {
138-
timeObserver = player.addPeriodicTimeObserver(
139-
forInterval: timePublishing,
140-
queue: .main
141-
) { [weak self] time in
136+
if let timePublishing = settings.timePublishing{
137+
timeObserver = player.addPeriodicTimeObserver(forInterval: timePublishing, queue: .global()) { [weak self] time in
138+
guard let self = self else{ return }
142139
Task { @MainActor in
143-
self?.delegate?.didPassedTime(seconds: time.seconds)
140+
self.delegate?.didPassedTime(seconds: time.seconds)
144141
}
145142
}
146143
}

‎Sources/swiftui-loop-videoplayer/view/player/ios/ExtPlayerUIView.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,8 @@ internal class ExtPlayerUIView: UIView, ExtPlayerProtocol{
141141
func setupPiP(delegate: AVPictureInPictureControllerDelegate) {
142142
// Check if PiP is supported
143143
guard AVPictureInPictureController.isPictureInPictureSupported() else {
144-
Task { @MainActor in
145-
try? await Task.sleep(nanoseconds: 1_000_000_000)
146-
self.onError(.notSupportedPiP)
144+
DispatchQueue.main.asyncAfter(deadline: .now() + 1){ [weak self] in
145+
self?.onError(.notSupportedPiP)
147146
}
148147
return
149148
}

‎Sources/swiftui-loop-videoplayer/view/player/mac/ExtPlayerNSView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ internal class ExtPlayerNSView: NSView, ExtPlayerProtocol {
7777
player = AVQueuePlayer(items: [])
7878

7979
super.init(frame: .zero)
80-
self.wantsLayer = true
8180

8281
addPlayerLayer()
8382
addCompositeLayer(settings)

0 commit comments

Comments
(0)

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