Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func timeObserver() {
- let interval = CMTimeMake(1, 2)
- let timeObserverToken = avPlayer?.addPeriodicTimeObserver(forInterval: interval, queue: DispatchQueue.main) { [weak self] time in
- let seconds = CMTimeGetSeconds(time)
- let secondsTime = Int(seconds.truncatingRemainder(dividingBy: 60.0))
- let MinutesTime = Int(seconds/60)
- if let duration = self?.avPlayer?.currentItem?.duration {
- let durationTime = CMTimeGetSeconds(duration)
- let AllTime = self?.avPlayer?.currentItem?.duration.seconds
- var min = "0:00"
- var startTimeHere = "0:00"
- if ((AllTime?.isNaN)!) {
- print("is nan")
- } else {
- let durationMin = (Int(AllTime!) % 3600) / 60
- let durationSec = (Int(AllTime!) % 3600) % 60
- min = "\(durationMin):\(durationSec)"
- startTimeHere = "\(MinutesTime):\(secondsTime)"
- }
- print("time observ " + String(describing: time))
- self?.timeDelegate?.changeTimeSlider(time: Float(seconds / durationTime), start: startTimeHere, duration: String(min))
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement