I loop my video played with AVFoundation video with the help of NSNotificationCenter and playerItemDidReachEnd:
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
self.playerItem = [AVPlayerItem playerItemWithAsset:asset];
self.avPlayer = [AVPlayer playerWithPlayerItem:self.playerItem];
[self.avPlayer addObserver:self forKeyPath:@"status"
options:0 context:AVMoviePlayerViewControllerStatusObservationContext];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[self.avPlayer currentItem]];
[self.VideoView setPlayer:self.avPlayer];
and
- (void)playerItemDidReachEnd:(NSNotification *)notification {
[notification.object seekToTime:kCMTimeZero];
[self startVideoLoop];
}
works great - but unfortunately not reliable. some times without any logic reason (seems to me) the player stops at the end of the movie without restarting again.
is it possible that NSNotificationCenter misses the end of the movie or the method playerItemDidReachEnd misses the notification message? stupid question. but I am unable to make head nor tail of it...