更新时间:2021-07-17 01:30:07
在事实上,我认为这是对苹果方面的bug。
In fact, I think it's bug on Apple side.
我发现了一个解决方法:设置showsPlaybackControls为YES AVPlayerViewController.player已设置后,
I found a workaround : set showsPlaybackControls to YES after the AVPlayerViewController.player have been set.
我修改您的样品与以下行,似乎没有更多的约束错误:
I modify your sample with the following lines and no more Constraint error appears :
@interface ViewController ()
@property(weak, nonatomic) AVPlayerViewController * playerViewController;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp4"];
NSURL *url = [[NSURL alloc] initFileURLWithPath: path];
AVPlayer * player = [AVPlayer playerWithURL:url];
self.playerViewController.player = player;
self.playerViewController.showsPlaybackControls = YES;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"AVPlayerSegue"]) {
self.playerViewController = segue.destinationViewController;
}
}
@end
请注意,文件 test.mp4
已添加到项目中。
Please note that the file test.mp4
have been added to the project.