[英]iPhone - issue in playing mp4 video with Swift - iOS
我使用此代码从资源中准备了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中播放视频吗?
您的代码看起来正确,没有任何问题。 您可能忘记了将该文件添加到您的目标成员身份。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.