|
|
|
@ -565,7 +565,14 @@ public class MusicService: NSObject { |
|
|
|
// 记录当前播放状态 |
|
|
|
let wasPlaying = isPlaying |
|
|
|
|
|
|
|
let time = CMTime(seconds: Double(positionMs) / 1000.0, preferredTimescale: CMTimeScale(NSEC_PER_SEC)) |
|
|
|
// 幂等短路:相同位置重复seek直接忽略 |
|
|
|
let currentSeconds = CMTimeGetSeconds(player.currentTime()) |
|
|
|
if !currentSeconds.isNaN && !currentSeconds.isInfinite { |
|
|
|
let currentMs = Int(currentSeconds * 1000) |
|
|
|
if currentMs == positionMs { return } |
|
|
|
} |
|
|
|
|
|
|
|
let time: CMTime = CMTime(seconds: Double(positionMs) / 1000.0, preferredTimescale: CMTimeScale(NSEC_PER_SEC)) |
|
|
|
|
|
|
|
player.seek(to: time) { [weak self] completed in |
|
|
|
if completed { |
|
|
|
@ -575,15 +582,10 @@ public class MusicService: NSObject { |
|
|
|
if wasPlaying { |
|
|
|
self?.player?.play() |
|
|
|
self?.isPlaying = true |
|
|
|
self?.updateMediaSessionPlaybackState(isPlaying: true) |
|
|
|
self?.startProgressTimer() |
|
|
|
} |
|
|
|
|
|
|
|
// 立即更新进度信息到系统媒体控制中心 |
|
|
|
self?.updateProgressInfoImmediately() |
|
|
|
|
|
|
|
// 通知Flutter层 |
|
|
|
self?.flutterChannel?.invokeMethod("onMediaSessionSeekTo", arguments: ["position": positionMs]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|