我正在尝试向我正在玩AVPlayer
的视频添加反向播放:
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
}
这确实可以正常工作,但是反向播放包含很多延迟而且它没有顺利播放,有没有办法解决这个问题。我在这里读过其他话题,但没有帮助。
答案 0 :(得分:3)
此代码对我来说可以在本地文件系统的反向播放avplayer中播放视频。
$(document).ready(function(){
$('#form_id').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields:{
first_name:{
validators:{
stringLength: {
min: 2,
},
notEmpty: {
message: 'Please supply your first name'
}
}
}
}
})
});
答案 1 :(得分:2)
尝试更换
videoPlayer.play()
videoPlayer.rate = -1
videoPlayer.playImmediately(atRate: -1)
答案 2 :(得分:1)
我不确定以下是否可以正常工作,因为我之前没有尝试过反向播放资产。我认为在开始比赛之前尝试结束是一个好主意。
player.seek(to: player.currentItem!.duration,
toleranceBefore: kCMTimeZero,
toleranceAfter: kCMTimeZero,
completionHandler: { (finished) in
player.play()
player.rate = -1
})
答案 3 :(得分:1)
var durTime: CMTime = queuePlayer.currentItem.asset.duration
durationTime = CMTimeGetSeconds(durTime)
if CMTIME_IS_VALID(durTime) {
queuePlayer.seek(toTime: durTime, toleranceBefore: kCMTimeZero, toleranceAfter: kCMTimeZero)
}
else {
print("In valid time")
}
现在将AVPlayer的比率设置为负值
queuePlayer.rate = -1