UIView 中的 AVPlayer 视图缺少控件

AVPlayer view in UIView is missing controls

在 AVPlayer 中,如果将 AVPlayer 添加到 UIView,则默认视频前进滑块和播放按钮不会显示

NSURL *videourl= [NSURL URLWithString:strUrl];
AVPlayer *player = [AVPlayer playerWithURL:videourl];         

AVPlayerViewController *playerViewController = [AVPlayerViewController new];            

playerViewController.player = player;

playerViewController.view.frame = ViewAV.bounds;

AVPlayerLayer* playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = ViewAV.bounds;

playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
//externalPlaybackVideoGravity
playerLayer.contentsGravity = AVLayerVideoGravityResizeAspect;

[ViewAV.layer addSublayer:playerLayer];
[ViewAV addSubview:playerViewController.view];

[playerViewController.player play];

尝试将 showsPlaybackControlsrequiresLinearPlayback 设置为真,

playerViewController.showsPlaybackControls = YES;
playerViewController.requiresLinearPlayback = YES;

目前,您没有将 playerViewController 添加为 child viewController,因此您将看不到任何内容。添加如下,

[self addChildViewController:playerViewController];
[self.view.layer addSublayer:playerLayer];
[self.view addSubview:playerViewController.view];