Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when an AVPlayerItem is finished playing? [duplicate]

Tags:

I've been looking through the AVPlayerItem and AVPlayer docs and there doesn't seem to be any callbacks for when the item is finished playing. I was hoping that there would be some sort of delegate callback that we can utilize or that AVPlayerActionAtItemEnd would provide a custom action for us to write.

How can i figure out a way to detect when AVPlayer has finished playing an item?

like image 378
3254523 Avatar asked May 06 '14 18:05

3254523


People also ask

How do I know when AVPlayer video is playing?

If you want to check the status of a played video - one of the best solutions is to add an observer to the AVPlayer item . The AVPlayerViewController doesn't notify about the ending of a video. This is why you need to check it by yourself. You should add the NotificationCenter observer to your playVideo() method.

How do I disable AVPlayer?

AVPlayer does not have a method named stop . You can pause or set rate to 0.0. Show activity on this post. I usually seekToTime 0.0, then pause.


1 Answers

It uses NSNotification to alert when playback is finished.

Register for the notification:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem]; 

Method to call when done:

-(void)itemDidFinishPlaying:(NSNotification *) notification {     // Will be called when AVPlayer finishes playing playerItem } 
like image 55
random Avatar answered Oct 07 '22 00:10

random