Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
func rewindVideo(by seconds: Float64) {
if let currentTime = player?.currentTime() {
var newTime = CMTimeGetSeconds(currentTime) - seconds
if newTime <= 0 {
newTime = 0
}
player?.seek(to: CMTime(value: CMTimeValue(newTime * 1000), timescale: 1000))
}
}
func forwardVideo(by seconds: Float64) {
if let currentTime = player?.currentTime(), let duration = player?.currentItem?.duration {
var newTime = CMTimeGetSeconds(currentTime) + seconds
if newTime >= CMTimeGetSeconds(duration) {
newTime = CMTimeGetSeconds(duration)
}
player?.seek(to: CMTime(value: CMTimeValue(newTime * 1000), timescale: 1000))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.