简体   繁体   English

显示内部存储中所有视频的列表

[英]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.

相关问题 如何使用 ListView 和 video_player(插件)显示设备存储中的视频列表? - How to display a list of videos from device storage using ListView & video_player (plugin)? 查询并列出Flutter手机内外存储上给定扩展名的所有文件? - Query and list all the files of a given extension on the phones internal and external storage in Flutter? 在颤动中从 Firebase 存储流式传输视频 - Streaming videos from firebase storage in flutter 如何从Flutter的内部和外部存储中获取所有PDF文件? - How to get all PDF files from internal as well as external storage in Flutter? 如何在 Flutter 中从内部和外部存储中获取所有 mp3 文件? - How to get all mp3 files from internal as well as external storage in Flutter? 如何在颤振中从设备的内部和外部存储中获取所有音频文件 - How to get all audio file from internal and external storage of a device in flutter 显示 json 列表中的所有数据 - Show all data from json list Flutter:从 Instagram 帖子中获取照片/视频并显示为水平列表视图 - Flutter: Get photos/videos from instagram posts and show as horizontal list view Flutter - 如何列出 Firebase 存储中的所有图像 - Flutter - How to list all images from Firebase Storage 在flutter中查询用户设备中的所有视频 - Query all the videos from user device in flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM