Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我试图从文档目录访问视频,但出现错误“;没有这样的文件或目录;_Ios_Swift_Iphone - Fatal编程技术网

Ios 我试图从文档目录访问视频,但出现错误“;没有这样的文件或目录;

Ios 我试图从文档目录访问视频,但出现错误“;没有这样的文件或目录;,ios,swift,iphone,Ios,Swift,Iphone,我已经下载了文件目录中的视频。我仔细检查了它是否存在于同一目录中。但获取错误“没有这样的文件或目录”。请帮帮我 我已经看完了SO提供的所有答案。但是没有找到答案 let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] var toURL = NSURL(string: "file:/\(documentsPath)")! toURL = toUR

我已经下载了文件目录中的视频。我仔细检查了它是否存在于同一目录中。但获取错误“没有这样的文件或目录”。请帮帮我

我已经看完了SO提供的所有答案。但是没有找到答案

let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]

var toURL = NSURL(string: "file:/\(documentsPath)")!

toURL = toURL.appendingPathComponent("1VIDEO.MOV")! as NSURL

var strPath = ""

print(toURL)

do {
        strPath = try String(contentsOf: toURL as URL)           
        print(strPath)
   }

catch let error as NSError {
        print(error)
   }

我应该以字符串格式获取本地文件路径。我应该能够访问它,并能够在avplayer中播放视频。

您创建URL的方式既麻烦又过时。发生此错误的原因是URL中缺少斜杠(方案为
文件://
)。无论如何,永远不要使用
URL(string
创建文件系统URL。也不要在Swift中使用
NSURL

请使用FileManager API。并且您不能将视频数据读取为
String

do {
    let documentsURL = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
    let toURL = documentsURL.appendingPathComponent("1VIDEO.MOV")
    let videoData = try Data(contentsOf: toURL)
    print(videoData)
catch {
    print(error)
}        

谢谢mag_zbc编辑我的问题谢谢您的回复。您正在将其转换为数据,但我想将其作为字符串传递给avplayer。我理解您的观点,但我不知道如何使用avplayer的数据。这是不可能的。您可以将URL传递到
avplayer
vadian,但我仍然面临相同的问题。“1VIDEO.MOV”文件无法打开,因为没有这样的文件“is
1VIDEO.MOV
拼写正确吗?区分大小写很重要。文件真的存在吗?是的,伙计。我已经检查过了。它存在于同一位置。