Reputation: 2730
I've been working on a tvOS app that has all the video content being displayed through AVPlayerViewController instances. I want to add a feature similar to Netflix that, when user is watching without user interaction for some time, it pauses the video and displays a message asking if the user is still watching. When doing that, I've found out it's impossible to pause the AVPlayer instance inside the AVPlayerViewController, both by calling [player pause]
and [player setRate:0.0]
, as it resumes playback immediately (it even has a UI response, as the player controls show up for a brief amount of time).
Is it possible for me to get rid of this auto-resume? I want to avoid releasing the player and also creating my own ViewController, as it would mean rewriting the user controls from scratch, but nothing else comes to mind. Any ideas?
Thanks
Upvotes: 0
Views: 346
Reputation: 4521
In tvOS10 the AVPlayer
inside AVPlayerViewController
works fine, you can pause it when you want it. Add this code inside your UIViewController
inherited from the AVPlayerViewController
:
self.player = AVPlayer.init(playerItem: AVPlayerItem.init(asset: AVAsset.init(url: URL.init(string: "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8")!)))
self.player?.play()
DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
self.player?.pause()
}
Upvotes: 0