AVPlayerViewController issues

519 views Asked by At

so I am trying to edit some source code from this project source...https://github.com/ariiyu/VideoPlayerSample

So, when I simply just try to replace the video path and file it crashes and I am not sure why??

Here is one of the ViewController source code...

import UIKit
import AVFoundation
import AVKit

class SecondViewController: AVPlayerViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

// I try to replace the string with my movie file here and crashes
        let moviePath = NSBundle.mainBundle().pathForResource("hogevideo", ofType: "mp4")!
        let url = NSURL(fileURLWithPath: moviePath)


        let playerItem = AVPlayerItem(URL: url)


        player = AVPlayer(playerItem: playerItem)


        player.play()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
1

There are 1 answers

0
Avijit Nagare On BEST ANSWER

In iOS 8 file system structure changed thats why you are getting crash use this function to get path of video in iOS 8

let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)

let moviePath = urls[0].URLByAppendingPathComponent("hogevideo.mp4")

println("And append your video file name to urls: \(moviePath)")