2

I'm using just_audio to play and cache medias. How can I check if the media is in just_audio cache directory, before I start playing it?

Thanks.

Cbeeapps
  • 21
  • 1
  • 2

1 Answers1

0

When you create a LockCachingAudioSource, you can pass in the cacheFile parameter which is the file where you would like the audio to be cached:

final source = LockCachingAudioSource(uri, cacheFile: ...);

If you don't specify the cacheFile parameter, just_audio will decide on its own where to store this cache file, and you can obtain this file via await source.cacheFile.

Then testing if that cache exists is easy:

final cacheFile = await source.cacheFile;
if (await cacheFile.exists()) {
  ...
}
Ryan Heise
  • 2,273
  • 5
  • 14