我似乎无法在视频中创建"完成"按钮。我在下面附上了我的代码:
- (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];
}
您没有正确使用AVPlayerViewController
类。这是您应该使用它的方式:
- (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];
}
这样,您将拥有"完成"按钮以及AVPlayerViewController
以及其他播放按钮(例如暂停/简历等)。