在 AVPlayer 中显示播放控件

Display playback controls in AVPlayer

我可以 运行 视频,但看不到暂停等控制按钮和与视频交互的滑块。询问了类似的查询(),但我没有遵循答案。

我得到了描述的答案。 See here。要显示播放、暂停按钮等系统播放控件,我们需要 AVPlayerViewController。 下面是 Objective-C.

中的实现
@interface ViewController ()
@property (strong,nonatomic) AVPlayerViewController *avPlayerViewController;
@property (strong,nonatomic) AVPlayer *avPlayer;
@end

    - (void)viewDidLoad {
    [super viewDidLoad];
    //URL for the file. It can be over HTTP or local file URL. 
    NSURL *folderURL=[NSURL fileURLWithPath:uploadFolderLocation];
    NSURL *movieURL=[folderURL URLByAppendingPathComponent:@"video.mp4"];

    self.avPlayer = [AVPlayer playerWithURL:movieURL];

    self.avPlayerViewController=[[AVPlayerViewController alloc]init];
    self.avPlayerViewController.player=self.avPlayer;    
}

- (IBAction)playButtonTapped:(id)sender {
    //Trigger the video to play

    //AVPlayer object can direct its visual output to AVPlayer. AVPlayerVC is a AVPlayerViewController. You can add it via objects in bottom-right corner.
    AVPlayerVC *avPLayerVC=[[AVPlayerVC alloc] init];
    avPLayerVC.player=self.avPlayer;

    [self addChildViewController:self.avPlayerViewController];
    [self.view addSubview:self.avPlayerViewController.view];
    self.avPlayerViewController.view.frame=self.view.frame;
    [self.avPlayerViewController.player play];
   }

带有控制按钮的视频图像: