2015-07-22 31 views
0

所以我想编辑从本项目源一些源代码... https://github.com/ariiyu/VideoPlayerSampleAVPlayerViewController发出

所以,当我只是简单地尝试更换视频路径和文件崩溃,我不知道为什么?

这里是视图控制器源代码中的一个......

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

} 
+0

确保您的文件存在。 – Bannings

+0

我其实只是想通了......我没有设置文件来定位项目。不过谢谢 – user3708224

回答

0

在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)") 
视频的路径
相关问题