Created
February 21, 2019 09:57
-
-
Save pgpt10/b41613df63769a53c67287fa8a4bc679 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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