Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache video url - then get it from cache again? #97

Open
ghost opened this issue Mar 14, 2017 · 1 comment
Open

Cache video url - then get it from cache again? #97

ghost opened this issue Mar 14, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented Mar 14, 2017

I download a video from a URL, and then i cache the Data to the cache using Cache.

Then later on I want to play that video i cached, so i check if it's cached, which it is, but then I put the Data into an url like (videoData being the NSData from the cache):

let url = URL(dataRepresentation: videoData as Data, relativeTo: nil)!

If i then try to play the video using the url, it's not working. Help please?

I know one could store the file locally, and the find the path to that file, but that defeats the purpose of caching a video using this library, because then you can't control expiration date etc.

And I see that the cached files get a .cache file type, so I can't reference the path directly as a .mp4 file and play it from the cached folder.

@ghost
Copy link

ghost commented Aug 12, 2017

Hello Daniel,

I'm running into the same issue. What I ended up doing as a temporary fix is to get the video data from the cache, then save it to the user temp directory as an MP4 file and getting the url for that instead.

if let cachedVideoData = cache.object(forKey: videoUrl.absoluteString) {
  let tempVideo = File<NSData>(path: Path.userTemporary + "temp.mp4")
  try! tempVideo.create()
  try! tempVideo.write(cachedVideoData, atomically: true)
  // use tempVideo.path.url
}

I'm using FileKit, but this can be done in the same way with FileManager

I don't really like this solution, but it will have to do for the time being.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants