我们可以用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)
}