I am trying to play a video in a container view called AVPlayerViewController however when you click on the player view to play the video it does not play. Is there any way to fix this? Here is the code I am using to try and play the video:
import UIKit
import AVKit
class IntroductionViewController: UIViewController {
var avPlayer: AVPlayer!
override func viewDidLoad() {
super.viewDidLoad()
}
func playVideo() {
let filepath: String? = Bundle.main.path(forResource: "Video", ofType: "mp4")
let fileURL = URL.init(fileURLWithPath: filepath!)
avPlayer = AVPlayer(url: fileURL)
let avPlayerController = AVPlayerViewController()
avPlayerController.player = avPlayer
avPlayerController.showsPlaybackControls = true
avPlayerController.view.frame = CGRect(x: 44, y: 128, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
// Turn on video controlls
avPlayerController.showsPlaybackControls = true
// play video
avPlayerController.player?.play()
self.view.addSubview(avPlayerController.view)
}
}