I have this json and I have to play a video
What is the best way to play video and validate or check if user watched whole video?
Video could be (Tiktok – Vimeo – Dayli Motion) video but no Youtube Video
I tried to use AVPlayer but it doesn’t work :
let videoURL = NSURL(string: "https://vimeo.com/601097657")
let player = AVPlayer(url: videoURL! as URL)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
playerViewController.player!.play()
}
I think the possible solution it could be a webView but I’m not sure if its possible to validate if user watched whole video
2
Answers
This is working for me.
This will print out how much of the video they have watched in seconds, which you could then check if this is equal to the total amount of time the video is.
Obviously you would have to implement methods to check if they have skipped part of the video or not, but that’s for another question.
Check out more info Time watched. and Total Video Time
AVPlayer sends notifications on occasions like that.
Simply subscribe to notifications you need. In your case you need
NSNotification.Name.AVPlayerItemDidPlayToEndTime
implementing this would look something like this:
And implement a selector for handling notification: