我正在尝试向我正在使用AVPlayer播放的视频添加反向播放: let videoURL = Bundle.main.url(forResource: "video", withExtension: "mov")videoPlayer = AVPlayer(url:videoURL!)let playerLayer = AVPlayerLayer(player: videoPlayer
let videoURL = Bundle.main.url(forResource: "video", withExtension: "mov") videoPlayer = AVPlayer(url:videoURL!) let playerLayer = AVPlayerLayer(player: videoPlayer) playerLayer.frame = self.view.frame videoView.layer.addSublayer(playerLayer) videoPlayer.play()
我搜索并发现如果我将AVPlayer的速率更改为-1,则电影以反向模式播放:
func reverseVideo() { videoPlayer.play() videoPlayer.rate = -1 }
这确实工作正常,但反向播放包含很多滞后,它不能顺利播放,是否有任何可能的方法来解决这个问题.我在这里读过其他话题,但没有帮助.
这个代码对我有用,可以在本地文件系统中反向播放avplayer中的视频.let duration = (self.playeritem?.asset.duration)! let durationSec = CMTimeGetSeconds((self.playeritem?.asset.duration)!) self.avPlayer?.seek(to: duration, toleranceBefore: kCMTimeZero, toleranceAfter: kCMTimeZero) self.avPlayer?.rate = -1