【问题标题】:Playing videos with flutter web and firebase storage使用 Flutter Web 和 Firebase 存储播放视频
【发布时间】: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 并获取它,但我不知道如何
任何建议将不胜感激

【问题讨论】:

    标签: flutter firebase-storage video-player


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2021-11-10
      • 1970-01-01
      • 2021-02-13
      • 1970-01-01
      • 2021-04-25
      • 2019-10-08
      • 2018-12-31
      • 1970-01-01
      • 2019-01-20
      相关资源
      最近更新 更多