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

时间:2018-04-25 16:40:40

标签: 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
}

}

1 个答案:

答案 0 :(得分:0)

尝试在Storyboard中的DataCellClass中查看AVPlayer的内容模式。确保将其设置为Aspect Fill

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