Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No "Done" button on AVPlayerViewController

Tags:

ios

I am using AVPLayerViewController to stream content. Playback works fine but I don't see "Done" button to dismiss the view.

Here is I how I setup and show the view controller

NSURL* url = [content localSessionUrl];
AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.player = [AVPlayer playerWithURL:url];
[self.navigationController pushViewController:playerViewController animated:YES];
[self.navigationController setNavigationBarHidden:YES];

Is it because I am pushing it on a navigationcontroller? enter image description here

like image 494
dev Avatar asked Jun 24 '15 20:06

dev


3 Answers

Instead of pushing or add child view, try to present the view. The Done button will automatically shown. Below is the code snippet.

-(void)playVideoWithUrl:(NSURL *)url{
    AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc]init];
    playerViewController.player = [[AVPlayer alloc]initWithURL:url];
    [self presentViewController:playerViewController animated:YES completion:nil];
    playerViewController.view.frame = self.view.frame;
    [playerViewController.player play];
}
like image 126
pkc456 Avatar answered Nov 12 '22 07:11

pkc456


Yes, the 'Done' button acts as a dismissal for a modal presentation style. If you are pushing the AVPlayerViewController onto the navigation stack you will need to handle the popping yourself.

like image 7
Tim Avatar answered Nov 12 '22 05:11

Tim


I think the issue is when you add the AVPlayerViewController view to the a view on the screen that takes up the whole screen, it treats it as already in fullscreen mode. The trick is to add it to a view that takes up a smaller portion of the screen.

Initially I did this:

// Setup an AVPlayerViewController
self.avPlayerViewController = [[AVPlayerViewController alloc] init];
if ([self.avPlayerViewController respondsToSelector:@selector(allowsPictureInPicturePlayback)]) {
    self.avPlayerViewController.allowsPictureInPicturePlayback = NO;
}

// Attach the Active Cloack AVPlayer to the AVPlayerViewController
AVPlayer *player = self.avPlayer;
self.avPlayerViewController.player = player;
self.avPlayerViewController.view.frame = self.view.bounds;
[self.view addSubview:self.avPlayerViewController.view];

// Setup the Parent Child relationshipo
[self addChildViewController:self.avPlayerViewController];
[self.avPlayerViewController willMoveToParentViewController:self];
[self.avPlayerViewController didMoveToParentViewController:self];

However, I then had the same problem that my player didn't have a Done button, so I couldn't exit the video.

I then modified my xib/storyboard and added a UINavigationBar to the top with a done button, and a UIView as a container underneath this. I then added the avPlayerViewController to this container view and the controls magically changed into a none full screen mode. I got a full screen button to take the player into full screen mode.

However I then had to create code to auto hide my nav bar and add a done button to this and a title etc...

like image 3
bandejapaisa Avatar answered Nov 12 '22 07:11

bandejapaisa