0

我一直试图让它工作,但似乎无法找到解决方案。我想在 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.
    }

}
4

1 回答 1

2

我相信您需要向 AVPlayer 提供一个指向 m3u8 文件或直接指向电影的 URL。一些示例 m3u8 文件可以在 Stack Overflow 和其他网站上找到。将您的视频路径更改为如下所示:

let videoPath = NSURL(string: "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8")
于 2015-08-21T18:48:03.657 回答