3

how to hide downloaded files from the gallery. I want to make an app like Amazone prime, Netflix where the downloaded video will be accessible only with the app.

SULPHURIC ACID
  • 278
  • 5
  • 19

1 Answers1

2

Use the path_provider package. It gives us options to access directory which is visible to the gallery and also a temporary directory that is hidden from the gallery. This is one way of addressing your requirement.

getTemporaryDirectory().then(
    (Directory dir) {
      final path = dir.path + '/' + fileName;
      final file = File(path);

      if (file.existsSync()) {
        // Perform operations
      } 

      else {
        file.createSync();
        // Perform operations
      }
    },
  );

Another approach to handle the requirement is to use flutter_cache_manager package. Application cache is hidden from all other applications including your OS from direct access. So caching your video might be a better option. When you try to play the video again, it will start playing from the cache instead of from the url you provided. If you are building an application like Netflix, caching is something you might be looking for. There are several settings that can be tweaked in there. For instance you can decide for how many days the video must be cached, maximum number of files that should be cached, etc. Check out the documentation. The code from the documentation works like a charm.

PS: I have worked on a similar application. I have an hunch that you might be looking for an option for streaming a video and caching it simultaneously. Hence, when you are playing it again, the cached version starts playing. If you are looking for such a feature, you might find these useful.

  1. cached_video_player
  2. Streaming and caching in Flutter (stackoverflow)
Abhay V Ashokan
  • 320
  • 3
  • 9