AvPlayer无法在Xcode 7中播放视频

时间:2015-08-21 00:26:02

标签: ios avplayer avplayerviewcontroller

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

}

1 个答案:

答案 0 :(得分:2)

我认为您需要将AVPlayer的URL提供给m3u8文件或直接提供给电影。在Stack Overflow和其他网站上可以找到一些example m3u8 files。 将您的视频路径更改为:

let videoPath = NSURL(string: "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8")