gpt4 book ai didi

ios - AVPlayer 摆脱顶部和底部的黑条/背景(Swift)

转载 作者:搜寻专家 更新时间:2023-11-01 06:30:12 27 4
gpt4 key购买 nike

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

UIViewController

import UIKit
import AVKit
import AVFoundation
private var looper: AVPlayerLooper?

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
let path = Bundle.main.path(forResource: "Innie-Kiss", ofType:"mp4")
let player = AVQueuePlayer(url: URL(fileURLWithPath: path!))
looper = AVPlayerLooper(player: player, templateItem: AVPlayerItem(asset: AVAsset(url: URL(fileURLWithPath: path!))))
let controller = AVPlayerViewController()
controller.player = player
let screenSize = UIScreen.main.bounds.size
let videoFrame = CGRect(x: 0, y: 200, width: screenSize.width, height: (screenSize.height - 130) / 2)
controller.view.frame = videoFrame
self.view.addSubview(controller.view)
player.play()
}

}

enter image description here

最佳答案

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

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

有关更多信息,请参阅:https://developer.apple.com/documentation/avfoundation/avplayerlayer/1388915-videogravity

关于ios - AVPlayer 摆脱顶部和底部的黑条/背景(Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48466254/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com