因此,我试图从这个项目源代码中编辑一些源代码.https://github.com/ariiyu/VideoPlayerSample
所以,当我只是简单地尝试替换视频路径并将其存档时,我不知道为什么??
这里有一个ViewController源代码..。
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.
}
}发布于 2015-07-22 05:08:11
在iOS 8中,文件系统结构发生了变化,这就是为什么要崩溃的原因,请使用此函数在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)")https://stackoverflow.com/questions/31553832
复制相似问题