How can I display all the videos from internal storage in flutter?

Forums FlutterHow can I display all the videos from internal storage in flutter?
Staff asked 2 months ago

Answers (1)

Add Answer
Parth Marked As Accepted
Staff answered 2 months ago

You have to add the below code in your file and you will get the list of your videos.

@override
void initState() {
  super.initState();
  getPermission();
}

getPermission() async {
  var status = await Permission.storage.request();
  if (status.isGranted) {
    getVideo();
  } else {}
}

getVideo() async {
  Directory dir = Directory('/storage/emulated/0/');
  String mp4Path = dir.toString();
  print(mp4Path);
  _files0 = dir.listSync(recursive: false, followLinks: false);

  for (FileSystemEntity entity in _files0) {
    String path = entity.path;
    if (path.endsWith('.mp4')) _videos.add(entity);
    print(path);
    allPath.add(path);
    allPath.remove("/storage/emulated/0/Android");
    print(allPath);
  }

  for (int i = 0; i < allPath.length; i++) {
    Directory dir = Directory('${allPath[i]}');

    String mp4Path = dir.toString();
    print("path ============ $mp4Path");
    _files = dir.listSync(recursive: true, followLinks: false);

    for (FileSystemEntity entity in _files) {
      String path = entity.path;
      if (path.endsWith('.mp4') || path.endsWith('.mkv')) _videos.add(entity);
    }
  }
  print(_videos);
  print(_videos.length);
  setState(() {});
}

 

 

Subscribe

Select Categories