我正在尝试使用 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()
}
答案 0 :(得分:0)
使用AVAsset
作为播放器的来源。
let currentVideoAsset = AVAsset(URL: outputFileURL)
self.player = AVPlayer(playerItem: AVPlayerItem(asset:currentVideoAsset))
答案 1 :(得分:0)
我找到了,我替换了这个
var videoURL = NSURL(fileURLWithPath: filePath)
用这个
composer.gotoScene("level1")
player.collision = onGlobalCollision
player:addEventListener ("collision", player)
正在工作..