HanekeSwift: Caching file, returning disk URL to retrieve later
Hey there!
I have a requirement to cache video data, but then retrieve the URL location for that data. The reason for this is an AVAsset cannot be created using NSData, only via a URL.
A very hacky (and very unreliable) way to do it now via Haneke is to do the following:
let cache = Haneke.sharedDataCache
cache.fetch(URL: URL).onSuccess { (data) in
// Hacky way of getting cache URL from Haneke
let path = DiskCache(name: "shared-data", capacity: UINT64_MAX).pathForKey(URL.absoluteString!)
let cacheURL = NSURL(fileURLWithPath: path)
}
What are your thoughts on how this should be handled? Should I forego using Haneke for this specific feature and build a disk-only cache instead?
James
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 1
- Comments: 21 (4 by maintainers)
I have the same issue, just for future references if somebody stuck with this, here my workaround (I’m reusing the player of SCRecorder)
Thank’s @jamescmartinez for show the way…
@frangeris i see… very interesting. I looked further into the issue and i noticed that the FIRST time you cal the cache onSuccess, it wont show up. if you call it again, however, it will show up. I made it so if the cache file doesnt exists, write the NSData to it, and read that. The in the future, the file will exist, and work fine
Hi guys, I tryied to do like @X901 but AVPlayer remains empty (not loading videos). If I check file existence, there is. But still, no video is displayed. Why this?