[英]Show list of all videos from internal storage
list all video files from a specific folder from internal storage and display them in flutter.列出内部存储中特定文件夹中的所有视频文件,并在 flutter 中显示它们。
i want to create an app to list all videos in internal storage and show them in gridview and play that video我想创建一个应用程序来列出内部存储中的所有视频并在 gridview 中显示它们并播放该视频
To get all the files from the storage you can use path_provider flutter package. With this, get the folder path, extract all the files with an extension of.mp4 (video file), and store it in List.要从存储中获取所有文件,您可以使用path_provider flutter package。这样,获取文件夹路径,提取所有扩展名为 .mp4 的文件(视频文件),并将其存储在列表中。
List<FileSystemEntity> _files = [];
void _getFiles() async {
Directory directory = await getExternalStorageDirectory();
List<FileSystemEntity> files = directory.listSync().where((entity) => entity.path.endsWith('.mp4')).toList();
setState(() {
_files = files;
});
}
Then you can use video_player Flutter package to play the video.然后就可以使用video_player Flutter package播放视频了。
GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
childAspectRatio: 1,
),
itemCount: _files.length,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
setState(() {
_controller = VideoPlayerController.file(_files[index])
..initialize().then((_) {
_controller.play();
});
});
},
child: Card(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.video_library,
size: 50,
),
SizedBox(height: 10),
Text(_files[index].path.split('/').last),
],
),
),
);
},
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.