使用 Flutter Web 和 Firebase 存储播放视频

Posted

技术标签:

【中文标题】使用 Flutter Web 和 Firebase 存储播放视频【英文标题】:Playing videos with flutter web and firebase storage 【发布时间】:2021-01-26 00:24:33 【问题描述】:

我正在尝试创建一个网站,用户可以在其中添加视频并查看这些视频。所有这些都存储在 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 并获取它,但我不知道如何 任何建议将不胜感激

【问题讨论】:

【参考方案1】:

您可以使用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

【讨论】:

以上是关于使用 Flutter Web 和 Firebase 存储播放视频的主要内容,如果未能解决你的问题,请参考以下文章

使用 Flutter Web 和 Firebase 存储播放视频

Firebase 和 Flutter 是不是支持在 Web 上一次性读取?

尝试使用 Firebase 远程配置运行 Flutter WEB 应用程序时出错 [关闭]

Flutter + Firebase Auth:有啥方法可以在 Web 上使用 Firebase 电话身份验证重新发送短信验证码?

是否可以在 Flutter Web 应用程序中使用 Firebase 管理 SDK?

相同的 Flutter Web 构建使用 `dhttp` 在本地运行,但使用 `firebase serve` 或 `firebase deploy` 失败