Skip to content

Instantly share code, notes, and snippets.

@Bayonetta
Last active August 29, 2015 14:05
Show Gist options
  • Save Bayonetta/3433a9cdb4ee4440a07a to your computer and use it in GitHub Desktop.
Save Bayonetta/3433a9cdb4ee4440a07a to your computer and use it in GitHub Desktop.
handle video completed
-(void)startPlaybackForItemWithURL:(NSURL*)url {
// First create an AVPlayerItem
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:url];
// Subscribe to the AVPlayerItem's DidPlayToEndTime notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
// Pass the AVPlayerItem to a new player
AVPlayer* player = [[[AVPlayer alloc] initWithPlayerItem:playerItem] autorelease];
// Begin playback
[player play]
}
-(void)itemDidFinishPlaying:(NSNotification *) notification {
// Will be called when AVPlayer finishes playing playerItem
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment