问题
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