Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.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
Swift avplayer流媒体功能正常,但本地文件无效_Swift_Streaming_Local_Avplayer - Fatal编程技术网

Swift avplayer流媒体功能正常,但本地文件无效

Swift avplayer流媒体功能正常,但本地文件无效,swift,streaming,local,avplayer,Swift,Streaming,Local,Avplayer,我试着播放本地mp3,如果本地文件不存在,我就会发送一个URL。简单的例子。 我不明白为什么流媒体可以工作,但不能播放本地文件 let localURL = AudioManager.localFileFromURL(AudioManager.file) if AudioManager.isFileDownloaded(localURL) { self.player = AVPlayer(URL: NSURL(string: localURL)!) self.playe

我试着播放本地mp3,如果本地文件不存在,我就会发送一个URL。简单的例子。 我不明白为什么流媒体可以工作,但不能播放本地文件

let localURL = AudioManager.localFileFromURL(AudioManager.file)

if AudioManager.isFileDownloaded(localURL)
{
      self.player = AVPlayer(URL: NSURL(string: localURL)!)
      self.player?.play()

}else{
      self.player = AVPlayer(URL: NSURL(string: AudioManager.file)!)
      self.player?.play()
}
LocalURL是磁盘上文件的url

isFiledownloaded函数用于检查文件是否在磁盘上。我确实验证了当文件在磁盘上时它返回true

AudioManager.file是一个外部URL

当我播放外置MP3时,会听到一些声音,但不是来自本地文件。

最终找到了它: 对于本地文件,不要使用NSURL(字符串:),而是使用NSURL(fileURLWithPath:)