简体   繁体   English

使AVPlayer全屏显示而无需装箱

[英]Make AVPlayer full screen without letterboxing

I'm trying to display a video on a login screen as seen on apps like Spotify. 我正在尝试在登录屏幕上显示视频,就像在Spotify之类的应用中看到的那样。

What I'm doing 我在做什么

To do this I'm using AVPlayer: 为此,我使用了AVPlayer:

self.videoPlayer = AVPlayer(playerItem: item)
self.videoView.player = self.videoPlayer
self.videoPlayer.play()

The videoView is a custom UIView class as described here . 该videoView是描述一个自定义UIView类在这里

I set the AVLayer's videoGravity to AVLayerVideoGravityResizeAspectFill: 我将AVLayer的videoGravity设置为AVLayerVideoGravityResizeAspectFill:

self.videoView.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill

The problem 问题

However, my video is still letterboxed when I try to make it fill out the bounds of my view: 但是,当我尝试将视频填充到视图范围内时,我的视频仍会带有字母框:

在此处输入图片说明

What I want 我想要的是

What I want is to have the video fill out the entire bounds without any black bars. 我想要的是使视频填充整个边界而没有任何黑条。 I don't care if part of the video is clipped: 我不在乎视频的一部分是否被剪切:

在此处输入图片说明

Additional information 附加信息

When I looked at the deprecated MPMoviePlayerController's scaling mode property , I found the following description of the aspectFill property: 当我查看不推荐使用的MPMoviePlayerController的scaleing模式属性时 ,发现了AspectFill属性的以下描述:

Scale the movie uniformly until the movie fills the visible bounds of the view. 均匀缩放影片,直到影片填满视图的可见范围。 Content at the edges of the larger of the two dimensions is clipped so that the other dimension fits the view exactly. 裁剪两个维度中较大者的边缘内容,以使另一个维度恰好适合视图。 The aspect ratio of the movie is preserved 保留电影的高宽比

Judging from this description, this is the exact behaviour I want. 从此描述来看,这是我想要的确切行为。 However, as already stated my video gets letterboxed. 但是,如前所述,我的视频带有信箱。 Am I doing something wrong or has Apple stopped supporting this type of scaling? 我是在做错什么,还是Apple停止支持这种缩放? If I don't care about part of the video being clipped, do I have to implement this scaling myself? 如果我不关心视频的一部分被裁剪,我是否必须自己实施缩放?

Any help is appreciated, thank you. 任何帮助表示赞赏,谢谢。

Ok so this is a tad embarrassing. 好的,这有点尴尬。 I finally realised that the video itself had the letter boxing baked into it :(. The scaling that the AVPlayer was doing was working just fine. 我终于意识到,视频本身已经加入了信箱:( .. AVPlayer所做的缩放工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM