Flutter - save Audio/Video file in invisible mode similarly Spotify/Youtube (Offline Downloads)

Viewed 194

I am working with Flutter and developing module like offline download media.

I got some solution for Video DRM tools like https://www.vdocipher.com/ but I want to implement it for audio.

The simplest way that I know about to store and hide the media as follow but it will be visible if I turn on show hidden files.

static Future<File> downloadAudioFile(String audioUrl) async {
    var hiddenFolder = '.nomedia';

    var directoryExternal = await getExternalStorageDirectory();
    final dir = Directory('${directoryExternal!.path}/$hiddenFolder');
    if ((await dir.exists())) {
    } else {
      dir.create();
    }
    final http.Response responseData = await http.get(Uri.parse(audioUrl));
    var uint8list = responseData.bodyBytes;
    var buffer = uint8list.buffer;
    ByteData byteData = ByteData.view(buffer);

    String fileName = audioUrl.split('/').last;
    File file = await File('${dir.path}/.${fileName}').writeAsBytes(
        buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
    return file;
  }

I want to do it for audio & video files, Please let me know if anyone have idea about it.

0 Answers
Related