When playing an .mp4 locally from device the media loops the playback as expected. When the media is from a server no notification is fired when the video stops playing
AVPlayer *avPlayer = [AVPlayer playerWithURL:[NSURL URLWithString:@"http://www.someurl.com/someMedia.mp4"]];
AVPlayerLayer *avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
avPlayerLayer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view.layer addSublayer:avPlayerLayer];
[avPlayer play];
// Loop video
avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[avPlayer currentItem]];
- (void)playerItemDidReachEnd:(NSNotification *)notification {
NSLog(@"Video ended");
AVPlayerItem *p = [notification object];
[p seekToTime:kCMTimeZero];
}
Checked Looping a video with AVFoundation AVPlayer? and How do I loop a video with AVFoundation without unwanted pauses at the end?
UPDATE
Thanks to ChrisH for this, creating a delay to allow for the video to be loaded from the server before observing player lops the video correctly
double delayInSeconds = 7.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[avPlayer currentItem]];
});