Reputation: 31
I can't seem to create the "Done" button at my video. I have attached my code below:
- (IBAction)playVideoButton:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Video1" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
AVPlayer *player = [AVPlayer playerWithURL:url];
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
//to view on full UIScreen
self.mc = controller;
controller.view.frame = self.view.bounds;
[self.view addSubview:controller.view];
[player play];
}
Upvotes: 2
Views: 336
Reputation: 33036
You were not using the AVPlayerViewController
class properly. Here is how you are supposed to use it:
- (IBAction)playVideoButton:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Video1" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
AVPlayer *player = [AVPlayer playerWithURL:url];
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
[self presentViewController:controller animated:YES completion:nil];
}
With that, you'll have the "Done" button comes with AVPlayerViewController
along with other playback buttons (e.g. pause/resume and etc.).
Upvotes: 1