Skip to content

Instantly share code, notes, and snippets.

@haidar786
Created December 2, 2019 14:24
Show Gist options
  • Save haidar786/30395e7c396a2a8bbc13ea3750be4278 to your computer and use it in GitHub Desktop.
Save haidar786/30395e7c396a2a8bbc13ea3750be4278 to your computer and use it in GitHub Desktop.
Future<List<VideoModel>> _getVideosFromStorage() async {
if (_videoModel == null) {
List<VideoModel> videoModel = [];
List<String> directories = [];
List<FileSystemEntity> files = [];
Directory directory = Directory('/storage/emulated/0/');
List<FileSystemEntity> allFiles =
directory.listSync(recursive: true, followLinks: false);
allFiles.forEach((file) {
if (file.path.endsWith('.mp4')) {
directories.add(file.parent.path);
files.add(file);
}
});
directories.toSet().toList().forEach((directory) {
List<Files> videoFiles = [];
Directory videoDirectory = Directory(directory);
files = videoDirectory.listSync();
files.forEach((file) {
if (file.path.endsWith('.mp4')) {
videoFiles.add(
Files(file, null),
);
}
});
videoModel.add(
VideoModel(directory.split('/').last, videoFiles),
);
});
_videoModel = videoModel;
}
return _videoModel;
}
//model
class VideoModel {
List<Files> files;
String folderName;
VideoModel(this.folderName, this.files);
}
class Files {
FileSystemEntity file;
Uint8List uInt8listThumbnail;
Files(this.file,this.uInt8listThumbnail);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment