AVPlayer摆脱了顶部和背景的黑条/背景。底部(斯威夫特)

时间:2018-01-26 17:11:56

标签: ios swift avplayer

快速提问,有谁知道如何摆脱视频顶部和底部的黑条?我刚刚开始使用AVPlayer,我只是在这里和那里删除代码,试图删除黑色图层。感谢那些可以帮助我的人,谢谢!

的UIViewController

summary(fit, fit.measures=TRUE)

enter image description here

2 个答案:

答案 0 :(得分:3)

您需要设置AVLayer的videoGravity。默认值为.resizeAspect,它将保留纵横比,顶部/底部或左/右有黑条。你想要的是.resize

您需要设置videoGravity的AVLayer是AVPlayer的图层属性。

有关详情,请参阅此处:https://developer.apple.com/documentation/avfoundation/avplayerlayer/1388915-videogravity

答案 1 :(得分:0)

#import AVKit

var playerController = AVPlayerViewController()
playerController.videoGravity = .resizeAspect
 /*playerController.videoGravity = .resizeAspectFill*/
playerController.view.backgroundColor = UIColor.white //set color as per super or custom view.

Note: If you set the videoGravity of the AVPlayerViewController. The default value is .resizeAspect then it is possible to visibility of black color(default) in background if you wants this color would similar to your super view's color then you must set superview's or custom view's color to your playercontroller's view background color.

示例:假设超级视图或自定义视图的背景色为白色,则必须将playerController视图的背景色设置为playerController.view.backgroundColor = UIColor.white,以使其看起来类似于UI中的相似颜色。

If you set playerController.videoGravity = .resizeAspectFill then it will fill the player content to super view or custom view, here also no black color would be shown. So choose either .resizeAspect  or resizeAspectFill as per your requirements.