令人惊讶的是,尽管进行了许多搜索,我仍无法找到答案。
我有一个已缓存的文件,我可以检索缓存目录和文件名,我相信它是网址?
这是获取文件然后播放它的代码
let cachedFilePath = getCachedFilePath.result as! String audioFileURL = cachedFilePath self.audioPlayerItem = AVPlayerItem(url: NSURL(string: audioFileURL!) as! URL)这是我打印audioFileURL返回的audioFileURL :
/用户/精灵/库/开发商/ CoreSimulator /设备/ A2FB00CE-B018-4FDF-9635-35FD6678DF8D /数据/容器/数据/应用/ E18B5E89-B973-4277-AA5C-1378C69D80CD /库/缓存/解析/ PFFileCache / 7e4a8fc0eb37b655b859e4959f986da2_The %20Name%20of%第二十条%20Wind%2017-92.mp3
玩家加载但它永远不会播放,只是坐在那里旋转。 所以我想知道我是否正确地将网址传递给玩家?
我在一个线程上读取使用file://之前但是没有用。
Surprisingly i have not been able to find an answer to this despite many searching.
I have a file that has been cached, i can retrieve the cache directory and file name which i believe to be the url?
this is code to get the file and then play it
let cachedFilePath = getCachedFilePath.result as! String audioFileURL = cachedFilePath self.audioPlayerItem = AVPlayerItem(url: NSURL(string: audioFileURL!) as! URL)This is what is returned if i print audioFileURL:
/Users/Genie/Library/Developer/CoreSimulator/Devices/A2FB00CE-B018-4FDF-9635-35FD6678DF8D/data/Containers/Data/Application/E18B5E89-B973-4277-AA5C-1378C69D80CD/Library/Caches/Parse/PFFileCache/7e4a8fc0eb37b655b859e4959f986da2_The%20Name%20of%20the%20Wind%2017-92.mp3
The player loads but it never plays, It just sits there spinning. so i am wondering if i am passing the url to the player correctly?
i read on one thread to use file:// before it but that didn't work.
最满意答案
在您创建NSURL的位置,您可以将参数名称string替换为fileURLWithPath
更改
NSURL(string: audioFileURL!)至
NSURL(fileURLWithPath: audioFileURL!)另外,为什么要将NSURL为URL ? 为什么不直接使用URL ?
In the place where you're creating an NSURL, you have the replace the argument name string to fileURLWithPath
Change
NSURL(string: audioFileURL!)to
NSURL(fileURLWithPath: audioFileURL!)Also, why are you casting NSURL to URL ? Why not use URL directly?
AVPlayer - 从本地URL播放(AVPlayer - Play from Local URL)令人惊讶的是,尽管进行了许多搜索,我仍无法找到答案。
我有一个已缓存的文件,我可以检索缓存目录和文件名,我相信它是网址?
这是获取文件然后播放它的代码
let cachedFilePath = getCachedFilePath.result as! String audioFileURL = cachedFilePath self.audioPlayerItem = AVPlayerItem(url: NSURL(string: audioFileURL!) as! URL)这是我打印audioFileURL返回的audioFileURL :
/用户/精灵/库/开发商/ CoreSimulator /设备/ A2FB00CE-B018-4FDF-9635-35FD6678DF8D /数据/容器/数据/应用/ E18B5E89-B973-4277-AA5C-1378C69D80CD /库/缓存/解析/ PFFileCache / 7e4a8fc0eb37b655b859e4959f986da2_The %20Name%20of%第二十条%20Wind%2017-92.mp3
玩家加载但它永远不会播放,只是坐在那里旋转。 所以我想知道我是否正确地将网址传递给玩家?
我在一个线程上读取使用file://之前但是没有用。
Surprisingly i have not been able to find an answer to this despite many searching.
I have a file that has been cached, i can retrieve the cache directory and file name which i believe to be the url?
this is code to get the file and then play it
let cachedFilePath = getCachedFilePath.result as! String audioFileURL = cachedFilePath self.audioPlayerItem = AVPlayerItem(url: NSURL(string: audioFileURL!) as! URL)This is what is returned if i print audioFileURL:
/Users/Genie/Library/Developer/CoreSimulator/Devices/A2FB00CE-B018-4FDF-9635-35FD6678DF8D/data/Containers/Data/Application/E18B5E89-B973-4277-AA5C-1378C69D80CD/Library/Caches/Parse/PFFileCache/7e4a8fc0eb37b655b859e4959f986da2_The%20Name%20of%20the%20Wind%2017-92.mp3
The player loads but it never plays, It just sits there spinning. so i am wondering if i am passing the url to the player correctly?
i read on one thread to use file:// before it but that didn't work.
最满意答案
在您创建NSURL的位置,您可以将参数名称string替换为fileURLWithPath
更改
NSURL(string: audioFileURL!)至
NSURL(fileURLWithPath: audioFileURL!)另外,为什么要将NSURL为URL ? 为什么不直接使用URL ?
In the place where you're creating an NSURL, you have the replace the argument name string to fileURLWithPath
Change
NSURL(string: audioFileURL!)to
NSURL(fileURLWithPath: audioFileURL!)Also, why are you casting NSURL to URL ? Why not use URL directly?
发布评论