private AssetFileDescriptor fetchFile(@NonNull Uri uri, @NonNull AssetManager am, @NonNull String fileName, @NonNull String identifier) throws IOException {
final File cacheFile = getContext().getExternalCacheDir();
final File file = new File(cacheFile, fileName);
try (final InputStream open = am.open(identifier + "/" + fileName);
final FileOutputStream fileOutputStream = new FileOutputStream(file)) {
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
}
//The code above is basically copying the assets to storage, and servering the file off of the storage.
//If you have the files already downloaded/fetched, you could simply replace above part, and initialize the file parameter with your own file which points to the desired file.
//The key here is you can use ParcelFileDescriptor to create an AssetFileDescriptor.
return new AssetFileDescriptor(ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY), 0, AssetFileDescriptor.UNKNOWN_LENGTH);
}