以下是我设置播放的方式:
movie = GPUImageMovie(url: url)
movie.playAtActualSpeed = true
movie.delegate = self
movie.addTarget(self)
movie.startProcessing()
播放完成后,GPUImageView
会显示视频文件的最后一帧。如何将其更改为第一帧?
答案 0 :(得分:1)
我们可以使用AVPlayerItem
并让AVPlayer
为我们处理播放:
func configure(url: URL) {
// player is AVPlayer instance declated as property
let playerItem = AVPlayerItem(url: url)
player.replaceCurrentItem(with: playerItem)
NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying(_:)), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: playerItem)
movie = GPUImageMovie(playerItem: playerItem)
movie.playAtActualSpeed = true
movie.addTarget(self)
movie.startProcessing()
}
func playerDidFinishPlaying(_ notification: Notification) {
guard player.currentItem == notification.object as? AVPlayerItem else { return }
player.seek(to: kCMTimeZero)
}