Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adding done button in AVPlayerViewController?

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.

like image 970
Jakfar Shodiq Avatar asked May 31 '26 15:05

Jakfar Shodiq


2 Answers

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
}
like image 59
Venk Avatar answered Jun 03 '26 07:06

Venk


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;
like image 20
Jakfar Shodiq Avatar answered Jun 03 '26 05:06

Jakfar Shodiq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!