Reputation: 16639
I used this code to ready the path of the mp4 file from resources and play it.
I used this code snippet:
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
}
}
i implement it with this function call:
playVideo("splash_video", type: "mp4");
the file is here:
the urlForFile
function always returns nil
I also tried to convert the video to m4v and mov, still get same result "nil"
so how on earth Can i play video in SWIFT !?
Upvotes: 0
Views: 1001
Reputation: 107221
Your code looks correct, there is no issue in that. Probably you forgot to add that file to your target membership.
Upvotes: 3