ios – 在AVPlayerLayer上拉伸视频

ios – 在AVPlayerLayer上拉伸视频,第1张

概述我使用以下代码在我的UIView上显示全屏视频: - (void)playMovie:(NSString *)name :(NSString *)type{ NSURL *movieURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:name ofType:type]]; self.movieA 我使用以下代码在我的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”的所有三个值…似乎没有任何改变.

我怎么解决?
谢谢

解决方法 你设置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];}
总结

以上是内存溢出为你收集整理的ios – 在AVPlayerLayer上拉伸视频全部内容,希望文章能够帮你解决ios – 在AVPlayerLayer上拉伸视频所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1114943.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存