|
|
|
@ -212,11 +212,12 @@ public class MusicService: NSObject { |
|
|
|
let totalDuration = (duration.isNaN || duration.isInfinite || duration <= 0) ? 0 : Int(duration * 1000) |
|
|
|
let progress = (totalDuration > 0 && currentTime >= 0) ? currentTime / duration : 0.0 |
|
|
|
|
|
|
|
let result = [ |
|
|
|
"currentPosition": currentPosition, |
|
|
|
"duration": totalDuration, |
|
|
|
"progress": progress.isNaN || progress.isInfinite ? 0.0 : progress |
|
|
|
] |
|
|
|
let result: [String: Any] = [ // Add explicit type annotation here |
|
|
|
"currentPosition": currentPosition, |
|
|
|
"duration": totalDuration, |
|
|
|
"progress": progress.isNaN || progress.isInfinite ? 0.0 : progress |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
// 添加调试日志 |
|
|
|
if totalDuration == 0 { |
|
|
|
@ -567,7 +568,7 @@ public class MusicService: NSObject { |
|
|
|
// 存储歌曲信息,用于状态变化时更新 |
|
|
|
objc_setAssociatedObject(playerItem, "songInfo", song, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// MARK: - KVO 观察者 |
|
|
|
override public func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { |
|
|
|
guard let playerItem = object as? AVPlayerItem else { return } |
|
|
|
@ -623,3 +624,4 @@ override public func observeValue(forKeyPath keyPath: String?, of object: Any?, |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |