0

我正在尝试从带有AVPlayer 的AVPlayerViewController的文档路径播放 mp4 视频,但它没有出现在屏幕上。我做错了什么?

这里是模拟器的截图:http: //postimg.org/image/xma60nfrf/

这是我的代码:

func startPlayer(filePath:String)
{
    let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask, true)
    let docsDir = dirPaths[0]


    let filePath = (docsDir as NSString).stringByAppendingPathComponent(videos[videoNo]._Name)

    playerVC=AVPlayerViewController()
    playerVC!.view.frame=self.view.bounds
    playerVC!.view.layer.zPosition = 1;


    var videoURL = NSURL(string: filePath)
    var player = AVPlayer(URL: videoURL!)
    var playerLayer = AVPlayerLayer(player: player)
    playerLayer.frame = playerVC!.view.bounds
    playerVC!.view.layer.addSublayer(playerLayer)

    playerVC!.player=player
    self.view.addSubview(playerVC!.view)

    playerVC!.player!.play()
}
4

2 回答 2

0

找到了,换了

var videoURL = NSURL(string: filePath)

有了这个

var videoURL = NSURL(fileURLWithPath: filePath)

并且正在工作..

于 2015-12-18T11:57:06.803 回答
0

用作AVAsset播放器的来源。

let currentVideoAsset = AVAsset(URL: outputFileURL)


self.player = AVPlayer(playerItem: AVPlayerItem(asset:currentVideoAsset))
于 2015-12-18T11:16:15.743 回答