有没有办法让边界时间观察者在5555毫秒时触发(然后暂停视频)?
我正在使用以下代码:
let url = NSBundle.mainBundle().URLForResource("colorfulStreak", withExtension: "m4v")!
let player = AVPlayer(URL: url)
player.actionAtItemEnd = .None
playerLayer.player = player
viewForPlayerLayer.layer.addSublayer(playerLayer)
let boundaryTime = NSValue(CMTime: CMTimeMakeWithSeconds(CMTimeGetSeconds(CMTimeMake(5555, 1000)), 10000))
print ("Assigned Boundary Time: \(CMTimeMakeWithSeconds(CMTimeGetSeconds(CMTimeMake(5555, 1000)), 10000))")
let observer = player.addBoundaryTimeObserverForTimes([boundaryTime], queue: dispatch_get_main_queue(), usingBlock: { [weak self] in
print("prior \(CMTimeGetSeconds((self?.player.currentTime())!))")
self?.player.pause()
print("after \(CMTimeGetSeconds((self?.player.currentTime())!))")
})
effectTimeObserver = observer
当边界观察者触发时,每次运行的输出都会有所不同:
指定边界时间:CMTime(值:555500,时间刻度:100000,标志:__C.CMTimeFlags(rawValue:1),纪元:0)
- 试验1:
事先5.555807083
在5.555963386之后
- 试验2:
事先5.555156239
在5.555312723之后