0

I'm trying to play a local video with this player I found online and this is the code that deals with getting the URL of the video. It appears it works for local videos but when I try it doesn't work.

private var filepath: String!
public var path: String! {
    get {
        return filepath
    }
    set {
        // Make sure everything is reset beforehand
        if(self.playbackState == .Playing){
            self.pause()
        }

        self.setupPlayerItem(nil)

        filepath = newValue
        let remoteUrl: NSURL? = NSURL(string: newValue)
        if remoteUrl != nil && remoteUrl?.scheme != nil {
            let asset = AVURLAsset(URL: remoteUrl!, options: .None)
            self.setupAsset(asset)

        } else {
            let localURL: NSURL? = NSURL(fileURLWithPath: newValue)
            let asset = AVURLAsset(URL: localURL!, options: .None)
            self.setupAsset(asset)

        }
    }
}

I put this code in another view controller where I want the video to run and set the path to the URL variable declared below...

let path = NSBundle.mainBundle().pathForResource("VideoName", ofType: "mov")

And it doesn't work for some reason. I'm most likely doing something wrong. What's going on? Reply if you need any more information. Thanks!

John Doe
  • 1,609
  • 2
  • 13
  • 22

1 Answers1

0

I think you want to use the browser to play a local video file?

For security reasons it is usually not possible for the browser to access a local file by itself, but you can allow the user choose a local video file and then play it in the browser. This makes sense from a security point of view as the user has to actually choose the video so they are by default approving the playback.

There is a good working example of a fiddle including the code to do this in this answer:

Community
  • 1
  • 1
Mick
  • 24,231
  • 1
  • 54
  • 120