3

我正在使用AVPlayerViewController并且无法显示完成按钮,也无法关闭播放器。也许你可以帮助我。这是我在 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;

需要帮助的各位,非常感谢。

4

2 回答 2

4
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
}
于 2016-03-23T10:52:18.227 回答
1

感谢您的回答。我已经找到了:)

我们可以使用这个,完成按钮可以自动显示。

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;
于 2016-03-23T12:46:01.747 回答