[英]Stretch video on AVPlayerLayer
I am using the following code to show a full-screen video on my UIView: 我使用以下代码在我的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];
}
The video is playing, but it doesn't fill (stretch if needed) the entire screen, but it only resizes maintaining its width/height ratio: I have tried all the three values of "videoGravity"... nothing seems to change. 视频正在播放,但它不会在整个屏幕上填充(如果需要的话),但它只调整大小以保持其宽高比:我已经尝试了“videoGravity”的所有三个值...似乎没有任何改变。
How can I solve? 我怎么解决? Thank you
谢谢
Your setting the Gravity then re-Initing the player try: 你设置Gravity然后重新进入玩家尝试:
- (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.movieLayer = [AVPlayerLayer playerLayerWithPlayer:self.moviePlayer];
[self.movieLayer setFrame:self.view.frame];
self.moviePlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
self.movieLayer.videoGravity = AVLayerVideoGravityResize;
[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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.