Search code examples
iosobjective-cavplayerviewcontroller

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.


Solution

  • 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
    }