我有这个代码:
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")!;
这是在seekBar上点击x坐标并寻找视频。该代码适用于日志视频,但对于短视频工作非常糟糕。当我点击短视频时,AVPlayer只在视频的开头或接近结尾处寻找,而不是在中间
打印:
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
val表示我不会寻求的秒的正确值。抱歉英语不好,我是意大利人