gpt4 book ai didi

swift - 如何直接播放保存在文档中的本地视频文件?

转载 作者:行者123 更新时间:2023-11-28 10:21:26 33 4
gpt4 key购买 nike

如何播放本地视频我正在将文件下载到本地文档,并在表格 View 中显示列表文件,但我不知道如何播放任何人都有想法

最佳答案

let fileManager = NSFileManager.defaultManager()

let urls = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)

if let documentDirectory:NSURL = urls.first { // No use of as? NSURL because let urls returns array of NSURL
// This is where the your video file should be in the documents directory
let yourFinalVideoURL = documentDirectory.URLByAppendingPathComponent("YOURVIDEO.mp4/mov")

if yourFinalVideoURL.checkResourceIsReachableAndReturnError(nil) {
// The file already exists, so just return the URL
let player = AVPlayer(URL: NSURL(fileURLWithPath: path))
let playerController = AVPlayerViewController()
playerController.player = player
self.presentViewController(playerController, animated: true) {
player.play()
}
}
}

希望对您有所帮助。

关于swift - 如何直接播放保存在文档中的本地视频文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34445174/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com