Skip to content

Instantly share code, notes, and snippets.

@pgpt10
Created February 21, 2019 09:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgpt10/b41613df63769a53c67287fa8a4bc679 to your computer and use it in GitHub Desktop.
Save pgpt10/b41613df63769a53c67287fa8a4bc679 to your computer and use it in GitHub Desktop.
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