自从升级到 iOS 12/XCode 10 和 Swift 4.2 以来,我一直在观察 AVPlayer 时间观察器的崩溃。播放相同视频时会发生崩溃,但并非每次都发生这种情况,这很奇怪。这是代码。我已经验证了间隔是 0.004 而不是 0。即使我手动将间隔设置为 1.0/30.0 而不是计算,也会发生这种情况。我怀疑崩溃与 Swift 4.2 或 iOS 12 中的某些更改有关。
let width = Double(self.playerView.bounds.width)
var interval = 0.5*duration.seconds/width
/* The time label needs to update at least once per second. */
if interval > 1.0 {
interval = 1.0
}
playerObserver = player.addPeriodicTimeObserver(forInterval: CMTime(seconds: interval, preferredTimescale: CMTimeScale(NSEC_PER_SEC)), queue: DispatchQueue.main, using: { [weak self] time in
self?.syncScrubber()
})
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVPeriodicTimebaseObserver initWithTimebase:interval:queue:block:] invalid parameter not satisfying: ((Boolean)(CMTimeCompare(interval, kCMTimeZero) > 0))'
*** First throw call stack:
(0x1e7a57ef8 0x1e6c25a40 0x1edab0be0 0x1eda65b18 0x10278eaec 0x10277d104 0x10277dc74 0x1e84c9d4c 0x1e84cc1e0 0x1e84c95d4 0x1eda91290 0x1043e3840 0x1043e4de4 0x1043f2a94 0x1e79e61bc 0x1e79e1084 0x1e79e05b8 0x1e9c54584