Reputation: 59
I'm using AVPlayerViewController and can't showing the Done button, and can't close the player also. maybe you can help me. This is my code in objective-c
UIView *view = self.view;
NSURL *fileURL = [NSURL URLWithString: _detailData[0]];
AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.player = [AVPlayer playerWithURL:fileURL];
self.avPlayerViewcontroller = playerViewController;
[self resizePlayerToViewSize];
[self dismissViewControllerAnimated:YES completion:nil];
[view addSubview:playerViewController.view];
[playerViewController.player play];
view.autoresizesSubviews = TRUE;
Need help guys, thank you very much.
Upvotes: 3
Views: 5594
Reputation: 59
thanks for your answer. I found it already :)
We can using this, and done button can shown automatically.
NSURL *fileURL = [NSURL URLWithString: _detailData[0]];
// create an AVPlayer
AVPlayer *player = [AVPlayer playerWithURL:fileURL];
// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
[player play];
// show the view controller
[self addChildViewController:controller];
[self.view addSubview:controller.view];
controller.view.frame = self.view.frame;
Upvotes: 1
Reputation: 5955
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Done" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0); // set your own position
[view addSubview:button]; // or you can add [playerViewController.view addSubview:button];
-(void)aMethod:(UIButton *)button {
// Remove playerViewController.view
}
Upvotes: 4