我正在尝试从带有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()
}