Reputation: 15
Beginner at Swift. My video does not fill it's frame. Here is my code. What do I need to implement for it to take up it's space that I set up in Storyboard?
import UIKit import AVFoundation import AVKit
class 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.
}
}
extension 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
}
}
Upvotes: 0
Views: 70
Reputation: 206
Try looking at Content Mode for the AVPlayer within your DataCellClass in Storyboard. Make sure it is set to Aspect Fill
This may help. https://useyourloaf.com/blog/stretching-redrawing-and-positioning-with-contentmode/
Upvotes: 0