Due to legal restrictions I need to prevent my app's users from skipping and fast-forwarding the content that is played by AVPlayerViewController.
I use playerViewController(:willResumePlaybackAfterUserNavigatedFrom:to:)
and playerViewController(:timeToSeekAfterUserNavigatedFrom:to:)
delegate methods to control the skipping behaviour. However, those delegate methods are only triggered for skip +/- 10, but not for fast-forwarding/rewinding.
Is there a way to prevent fast-forwarding in addition to skipping in AVPlayerViewController?
Here is an example of the code I use:
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
setUpPlayerViewController()
}
private func setUpPlayerViewController() {
let playerViewController = AVPlayerViewController()
playerViewController.delegate = self
guard let url = URL(string: "https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8") else {
debugPrint("URL is not found")
return
}
let playerItem = AVPlayerItem(url: url)
let player = AVPlayer(playerItem: playerItem)
playerViewController.player = player
present(playerViewController, animated: true) {
playerViewController.player?.play()
}
}
}
extension ViewController: AVPlayerViewControllerDelegate {
public func playerViewController(_ playerViewController: AVPlayerViewController, willResumePlaybackAfterUserNavigatedFrom oldTime: CMTime, to targetTime: CMTime) {
// Triggered on skip +/- 10, but not on fast-forwarding/rewinding
print("playerViewController(_:willResumePlaybackAfterUserNavigatedFrom:to:)")
}
public func playerViewController(_ playerViewController: AVPlayerViewController, timeToSeekAfterUserNavigatedFrom oldTime: CMTime, to targetTime: CMTime) -> CMTime {
// Triggered on skip +/- 10, but not on fast-forwarding/rewinding
print("playerViewController(_:timeToSeekAfterUserNavigatedFrom:to:)")
return targetTime
}
}