I have an animated menu to start some videos. The video is implemented as one skVideoNode . When I press a menu button for the first time, the animation of the menu as well as the video start is delayed. I thought something have to load, so I preloaded all texture. The same, after some testing, it accurs at the place where the video is started. What could be the reason.
I initialize the avPlayer already at the program start, then I change only the item. the menu animated is triggered before but stops also for a seconds. why?
func setupVideo() {
let fm = FileManager.default
let urls = fm.urls(for: .documentDirectory, in: .userDomainMask)
// if let url = urls.first as? URL {
if let url = urls.first {
let urlPath : String = url.path + "/" + "load.mp4"
let item = AVPlayerItem(url: URL(fileURLWithPath: urlPath) )
let vPlayer = AVPlayer(playerItem: item)
avPlayer = vPlayer
}
}
trigged with the menu button
if let url = urls.first {
let urlPath : String = url.path + "/" + videoName
let item = AVPlayerItem(url: URL(fileURLWithPath: urlPath) )
avPlayer.replaceCurrentItem(with: item)
let timeInterval: CMTime = CMTimeMakeWithSeconds(0.5, 10)
avPlayerTimeObserver = avPlayer.addPeriodicTimeObserver(forInterval: timeInterval, queue: DispatchQueue.main) { (elapsedTime: CMTime) -> Void in
let floatTime = Float(CMTimeGetSeconds(elapsedTime))
// print("elapsedTime now:", CMTimeGetSeconds(elapsedTime) )
self.avPlayerObserveTime(floatTime: floatTime)
} as AnyObject
}