我正在使用以下代码在我的 UIView 上显示全屏视频:
- (void)playMovie:(NSString *)name :(NSString *)type
{
NSURL *movieURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:name ofType:type]];
self.movieAsset = [AVAsset assetWithURL:movieURL];
self.movieItem = [[AVPlayerItem alloc] initWithAsset:self.movieAsset];
self.moviePlayer = [[AVPlayer alloc] initWithPlayerItem:self.movieItem];
self.moviePlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
self.movieLayer.videoGravity = AVLayerVideoGravityResize;
self.movieLayer = [AVPlayerLayer playerLayerWithPlayer:self.moviePlayer];
[self.movieLayer setFrame:self.view.frame];
[self.view.layer addSublayer:self.movieLayer];
[self.moviePlayer addObserver:self forKeyPath:@"status" options:0 context:nil];
// Schedule stop after 6 seconds
[NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:@selector(stopCurrentMovie:) userInfo:nil repeats:NO];
}
视频正在播放,但它没有填满(如果需要,可以拉伸)整个屏幕,但它只会调整大小以保持其宽度/高度比:我已经尝试了“videoGravity”的所有三个值......似乎没有任何改变。
我该如何解决?谢谢