How to hide AVPlayerViewController control bar?

房东的猫 提交于 2019-12-10 11:35:39

问题


I've implemented iAd's Preroll Video Ad and I want to guarantee that my user will watch the entire advertisement. How do I hide the AVPlayerViewController's control bar so the user can not tap "Done" and get out of the video before it finishes?

self.canDisplayBannerAds = YES;
[AVPlayerViewController preparePrerollAds];
player = [[AVPlayerViewController alloc] init];
player.showsPlaybackControls = NO;
player.delegate = self;

回答1:


You can use this code to do the same. You need to call play when you present the controller.

playerItem = [[AVPlayerItem alloc] initWithURL:url];
if(playerItem) {
  player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
  playerViewController = [[AVPlayerViewController alloc] init];
  playerViewController.player = _player;
  [playerViewController setShowsPlaybackControls:NO];
  [parentViewController presentViewController:playerViewController animated:YES completion:^{
  [playerViewController.player play];
}];



回答2:


Simple code

// create an AVPlayer
AVPlayer *player = [AVPlayer playerWithURL:videoURL];

// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
controller.showsPlaybackControls = FALSE;


来源:https://stackoverflow.com/questions/33828940/how-to-hide-avplayerviewcontroller-control-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!