How to detect when AVPlayer video ends playing?

To get the AVPlayerItemDidPlayToEndTimeNotification your object needs to be an AVPlayerItem. To do so, just use the .currentItem property on your AVPlayer Now you will get a notification once the video ends! See my example: let videoPlayer = AVPlayer(URL: url) NSNotificationCenter.defaultCenter().addObserver(self, selector: “playerDidFinishPlaying:”, name: AVPlayerItemDidPlayToEndTimeNotification, object: videoPlayer.currentItem) func playerDidFinishPlaying(note: NSNotification) { print(“Video Finished”) } Swift … Read more

How to reduce iOS AVPlayer start delay

For iOS 10.x and greater to reduce AVPlayer start delay I set: avplayer.automaticallyWaitsToMinimizeStalling = false; and that seemed to fix it for me. This could have other consequences, but I haven’t hit those yet. I got the idea for it from: https://stackoverflow.com/a/50598525/9620547

Looping a video with AVFoundation AVPlayer?

You can get a Notification when the player ends. Check AVPlayerItemDidPlayToEndTimeNotification When setting up the player: ObjC avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemDidReachEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:[avPlayer currentItem]]; this will prevent the player to pause at the end. in the notification: – (void)playerItemDidReachEnd:(NSNotification *)notification { AVPlayerItem *p = [notification object]; [p seekToTime:kCMTimeZero]; } this will rewind … Read more

capturing self strongly in this block is likely to lead to a retain cycle

The capture of self here is coming in with your implicit property access of self.timerDisp – you can’t refer to self or properties on self from within a block that will be strongly retained by self. You can get around this by creating a weak reference to self before accessing timerDisp inside your block: __weak … Read more