需要將視頻文件轉換爲NSData,然後返回到可播放的URL。 NSData部分如下:NSData 2視頻網址?
let videoNSD = NSData(contentsOfURL: videoPreview!)
// videoNSD is uploaded to cloud and then retrieved..
func playNSDataVideoPreview(videoNSD: NSData)
{
// how to play in AVPlayer?
let playerController = AVPlayerViewController()
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let documentsDirectory = paths[0]
let filePath = documentsDirectory + "/" + "nsdfile-1234.mp4"
let nsdURL = NSURL(fileURLWithPath: filePath)
videoNSD.writeToURL(nsdURL, atomically: true)
mediaPlayer = AVPlayer(URL: nsdURL)
playerController.player = mediaPlayer
mediaPlayer.play()
}
在AVPlayer中播放的最佳做法是什麼?
謝謝...
如果視頻太大,該怎麼辦?比RAM更多? – ogres
這是用於小片段vids。我將添加代碼來限制..謝謝你的擡頭.. – DolfinMia
會更好地下載爲一個文件,然後打開播放器從文件 – ogres