i have this code :
let punto = sender.locationInView(self.barraVideo).x
let larghezzaImg : Double = Double((self.barraVideoInvisTocco?.frame.width)!)
let percTocco : Double = (100 / larghezzaImg) * Double(punto)
let lunghezzaVideo : Double = Double(CGFloat((avPlayer?.currentItem?.asset.duration.value)!) / CGFloat(1000.0));
let frameRate : Int32 = (avPlayer?.currentItem?.currentTime().timescale)!
let secondo : Float64 = Float64((lunghezzaVideo/100)*percTocco)
print("Val : \(secondo)");
avPlayer?.currentItem?.seekToTime(CMTimeMakeWithSeconds(secondo, frameRate))
avPlayer?.play()
videoInPlay = true;
playPauseBtn!.image = UIImage(named: "iconaPausa.png")!;
That recive a x cordinate of a tap on the seekBar and seek the video. The code works with logs video but work very bad with short videos. When i tap on the short video the AVPlayer seek only near the begining or near the end of the video, not in the middle
print :
Val : 3.36008475976495
Val : 7.14189817632069
Val : 13.3303201306846
Val : 3.70388597945183
Val : 3.93308679257642
Val : 3.24548435320265
Val : 3.70388597945183
Val : 18.8311396456748
Val : 27.0823689181601
Val : 40.1468152662618
Val : 51.3776551093667
Val : 17.2267339538027
Val : 9.54850671412889
Val : 23.4151559081666
Val : 37.6256063218913
The val rappresents the right value of seconds where i wont to seek. Sorry for bad english, i'm italian