HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 在AVPlayerLayer上拉伸视频大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用以下代码在我的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上拉伸视频所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。