GPUImageMovie:播放完成后如何显示视频的第一帧?

时间:2017-05-29 06:11:45

标签: ios swift video gpuimage

以下是我设置播放的方式:

movie = GPUImageMovie(url: url)
movie.playAtActualSpeed = true
movie.delegate = self
movie.addTarget(self)
movie.startProcessing()

播放完成后,GPUImageView会显示视频文件的最后一帧。如何将其更改为第一帧?

1 个答案:

答案 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)
}