[英]How to make video fill frame using 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
}
}
尝试在情节提要中的DataCellClass中查看AVPlayer的“内容模式”。 确保将其设置为“纵横比填充”
这可能会有所帮助。 https://useyourloaf.com/blog/stretching-redrawing-and-positioning-with-contentmode/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.