Created
December 2, 2019 14:24
-
-
Save haidar786/30395e7c396a2a8bbc13ea3750be4278 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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