我一直试图让它工作,但似乎无法找到解决方案。我想在 viewDidLoad 上开始播放视频。我可以让 AVPlayerViewController 显示,但没有视频播放。任何建议将不胜感激。
import UIKit
import AVFoundation
import AVKit
class ViewController: UIViewController {
var videoPlayer = AVPlayerViewController()
let videoPath = NSURL(string: "https://youtu.be/dWYNNQdD6rY")
override func viewDidLoad() {
super.viewDidLoad()
let player = AVPlayer(URL: videoPath!)
let playerController = AVPlayerViewController()
playerController.player = player
self.addChildViewController(playerController)
self.view.addSubview(playerController.view)
playerController.view.frame = self.view.frame
player.play()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}