2015-07-22 26 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)") 
視頻的路徑
相關問題