I am building an app in Swift on Xcode 7.2
I added a video to my ViewController. Here\'s the code:
import UIKit
import AVKit
import AVFoundation
class G
Maybe the problem is that filenames are case-sensitive on the iPhone, but not in the simulator?
Thanks for all the hints. I created these:
let path = NSBundle.mainBundle().pathForResource("video", ofType:"m4v")
And called them in the button action:
@IBAction func playButtonPressed(sender: AnyObject) {
playerView = AVPlayer(URL: NSURL(fileURLWithPath: path!))
playerViewController.player = playerView
self.presentViewController(playerViewController, animated: true){
self.playerViewController.player?.play()}}
And it WORKS!!
Thanks!
I might be reading this wrong, but you appear to be using a file located on your computer?
Because your path you was using is from simulator, on real device it changed. if you added this file to your project, you can get this url via:
func getDocumentsURL() -> NSURL {
let documentsURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
return documentsURL
}
func fileInDocumentsDirectory(filename: String) -> String {
let fileURL = getDocumentsURL().URLByAppendingPathComponent(filename)
return fileURL.path!
}