As far as I understand, for passing data from a Class to a UIViewController, I used protocols & delegate, and it works like charm. What I did:
In Player class, I added:
public protocol PlayerDelegate {
func playerPlaybacksTimer(NSString: String)
}
public convenience init() {
player.addPeriodicTimeObserverForInterval(CMTimeMake(1, 100), queue: dispatch_get_main_queue()) {
[unowned self] time in
let timeString = String(format: "%02.2f", CMTimeGetSeconds(time))
self.delegate?.playerPlaybacksTimer(timeString)
}
}
and then I added the protocol & protocol method in UIViewController:
class ViewController: UIViewController, PlayerDelegate {
func playerPlaybacksTimer(currentTime: String) {
durationSlider.value = Float(currentTime)!
print(currentTime)
}
}
Until here, it works nicely and I can get the current time of the player. However, now, I am trying to do the reverse, so send data from ViewController to Class. (To make what I want to achieve clear, using above approach, I assigned the current playing time of Player to a UISlider and the slider's value is changing as the video goes on)
At this point, I want to make the user to be able to change the UISlider value and manipulate/change the current playing time of the video. As far as I understand, I should use seekToTime
but I am completely lost on how to achieve that.
Should I set another protocol from the ViewController to the Class? What is the way to achieve that the UISlider's value is assigned to the current value?
At least, please guide me on the first step I should take to pass data from the VC to the Class? I assume once I get the slider's value in the Player class, I can try playing with the SeekToTime
approach to understand and apply.
P.S: I am using the demo project of Player (which is a quiet straight forward library) that uses AVPlayer & AVFoundation
P.S 2: I asked another question on similar topic and opened a bounty here. Please also check there, for more detailed explanation on my issue (and possibly get a 50 points bounty).