I am using Player library, that is using AVPlayer & AVFoundation, which is quiet convenient for my case. I successfully managed to play the video and add a slider. I set the slider's min to 0 and max to duration of the video..
At this point, in order to connect slider to current playtime, I used this answer, on StackOverflow. I setup a protocol and used addPeriodicTimeObserverForInterval
, so slider is linked to the currentTime and moving as video moves along successfully.
Now, here is my problem. I want to do the reverse and make - when slider moves, set currentTime of the video (forward,backward).
I made some research and I found out that it's seekToTime
that I should link the slider.value
(sender.value
in my case) but, I couldn't understand how to apply it to Player. How can I make the slider to control the currentTime?
I am not sure if I am right, but as far as I understand, the first step should be:
protocol UserSetsTheTimeDelegate
{
func userSetsTheTime(result: Int)
}
class ViewController: UIViewController, PlayerDelegate {
...
func sliderValueDidChange(sender:UISlider!) {
print("value--\(sender.value)")
self.delegate?.userSetsTheTime(sender.value)
}
}
And add, I think I should add the UserSetsTheTimeDelegate
in Player.swift, but I got confused here.
Update:
I realised that I can send the data to the Player.swift by using an instance in ViewController and adding a method in Player class. This is the first step. But now, as currentTime is getting updated (with modifying the slider) so quickly, it doesn't let me manipulate the slider value.