swift - 如何使用 AVFoundation 制作视频填充框

标签 swift avfoundation

Swift 初学者。我的视频没有填满它的框架。这是我的代码。我需要实现什么才能让它占用我在 Storyboard 中设置的空间?

导入UIKit 导入AVFoundation 导入AVKit

ViewController 类:UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

扩展 ViewController:UITableViewDelegate、UITableViewDataSource {

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return 1
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: "cellview", for: indexPath) as! DataCellClass

    let videourl = URL(fileURLWithPath: Bundle.main.path(forResource: "sample", ofType: "mp4")!)

    let avPlayer = AVPlayer(url: videourl as URL)

    cell.PlayerView?.playerLayer.player = avPlayer

    cell.PlayerView.player?.play()

    return cell
}

}

最佳答案

尝试在 Storyboard 的 DataCellClass 中查看 AVPlayer 的内容模式。确保将其设置为宽高比填充

这可能会有所帮助。 https://useyourloaf.com/blog/stretching-redrawing-and-positioning-with-contentmode/

关于swift - 如何使用 AVFoundation 制作视频填充框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50027344/

相关文章:

swift - 如何根据 CVcalendar 中的特定时间发出每日本地通知?

swift - 使用管理器 session 配置设置默认的 baseURLString

ios - 在 iOS 中合并/重叠捕获的视频

ios - 没有 AVAsset 的纯色的 AVMutableComposition

ios - AVFoundation:isExposureModeSupported 为 AVCaptureExposureModeAutoExpose 返回 FALSE

iOS、swift、scenekit、场景加载事件

swift - 按下时更改按钮标签/文本

uitableview - 从选定行获取 PFObject 并保存到另一个解析类

ios - iOS无需用户交互即可拍摄多张照片

swift - Swift,AVFoundation startRecording 当 Recording 为 true 时