我使用此代码从资源中准备好mp4文件的路径并播放它。
我使用了这段代码:
func playVideo(videoName : String, type: String) {
let url = urlForFile(videoName, fileType: type)
if let url = url {
/* use the scene */
moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = moviePlayer {
player.view.frame = self.view.bounds
player.controlStyle = MPMovieControlStyle.None
player.prepareToPlay()
player.scalingMode = .AspectFill
self.view.addSubview(player.view)
}
println("it started!")
} else {
/* the scene couldn't be intialized */
finishedVideo()
}
}
func urlForFile (fileName : String, fileType: String) -> NSURL? {
let path = NSBundle.mainBundle().pathForResource(fileName, ofType:fileType)
if let path = path {
return NSURL(fileURLWithPath:path)
} else {
return nil
}
}
我用这个函数调用实现它:
playVideo("splash_video", type: "mp4");
文件在这里:
urlForFile
函数始终返回nil
我还尝试将视频转换为m4v和mov,仍然得到相同的结果" nil "
那么我怎样才能在SWIFT播放视频!?
答案 0 :(得分:3)
您的代码看起来正确,没有问题。您可能忘了将该文件添加到目标会员资格中。