简体   繁体   中英

AVPlayerViewController issues

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.
    }

}

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)")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM