AVPlayerViewController 物镜 C 上没有"Done"按钮



我似乎无法在视频中创建"完成"按钮。我在下面附上了我的代码:

- (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以及其他播放按钮(例如暂停/简历等)。

最新更新