flutter - 使用 Flutter Web 和 Firebase 存储播放视频
问题描述
我正在尝试制作一个网站,用户可以在其中添加视频并查看这些视频。所有这些都存储在 Firebase 存储中。这就是我存储它的方式
fb.StorageReference storageRef = fb.storage().ref('videos/$chapter)');
fb.UploadTaskSnapshot uploadTaskSnapshot = await storageRef.put(videoFile, fb.UploadMetadata(contentType: 'video/mp4')).future;
await uploadTaskSnapshot.ref.getDownloadURL().then((value){
videoUrl = value.toString();
});
snapshot.reference.collection("videos").add({
"chapter":chapter,
"class":grade,
"description":description,
"notes":notes,
"subject":subject,
"video":videoUrl,
"timestamp":DateTime.now().millisecondsSinceEpoch.toString()
});
我使用普通的视频播放器插件播放它们。现在的问题是当我存储它时,我得到一个像
https://firebasestorage.googleapis.com/v0/b/studyme-me.appspot.com/o/videos%2Ff )?alt=media&token=ec4fea39-032b这样的网址-438f-8122-f8e042c1c9c7
但是flutter web中的视频播放器需要.mp4或.wav或类似的文件。我该怎么做才能让视频播放器播放这些(我认为不可能),或者我可以为此获取 .mp4 文件。也许我可以使用 firebase 存储来打开这个 url 并获取它,但我不知道
任何建议会如何得到赞赏
解决方案
您可以使用VideoPlayerController插件来做到这一点
VideoPlayerController controller = VideoPlayerController.network('your-video-url',);
//Play/Pause Video:
FloatingActionButton(
onPressed: () {
// Wrap the play or pause in a call to `setState`. This ensures the
// correct icon is shown
setState(() {
// If the video is playing, pause it.
if (_controller.value.isPlaying) {
_controller.pause();
} else {
// If the video is paused, play it.
_controller.play();
}
});
},
// Display the correct icon depending on the state of the player.
child: Icon(
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
),
)
'''
more examples in the link above
推荐阅读
- css - 在 Tailwind CSS 中对齐内容
- java - 除非我先输入,否则为什么 System.out.print() 不会打印?
- flutter - 命名参数“产品”是必需的,但没有相应的参数。飘飘然
- r - 在 R 中的 treedata 对象列表中添加一个新列
- python-3.x - 具有多个树视图小部件的 Python 树视图标题背景颜色
- node.js - 使用 Electron/Nodejs 将数据从服务器传递到 html
- visual-studio-2019 - Visual Studio 2019 - 无法将网站发布到本地文件夹
- c++ - 从第二个字符串组成一个字符串,字符顺序
- html - CSS在悬停时将背景颜色应用于div,但仅当链接悬停时
- node.js - 如何使用 Nodejs 将超链接添加到现有 PDF?