By pressing a button in my app it plays a local video using the AVPlayerViewController.
However when the end of the video is reached the video just stops and the player is still open.
I want the player to automatically close when the video has finished playing and return to the previous view (with the button).
This is my code:
-(IBAction)playVideo1;
{
NSURL *videoURL = [[NSBundle mainBundle]URLForResource:@"video1" withExtension:@"mp4"];
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
[player play];
[self addChildViewController:controller];
[self.view addSubview:controller.view];
controller.view.frame = self.view.frame;
}