【问题标题】:Undefined name streamManifest in youtube_explode_dart package flutteryoutube_explode_dart 包中未定义的名称 streamManifest
【发布时间】:2021-11-07 22:50:04
【问题描述】:

我在使用颤振中的 youtube_explode_dart 包的文档时遇到问题。我正在尝试使用此包和 firebase 存储构建音乐流应用程序,但它们在文档代码中似乎有些错误(代码如下)

// Get highest quality muxed stream
var streamInfo = streamManifest.muxed.withHigestVideoQuality();

// ...or highest bitrate audio-only stream
var streamInfo = streamManifest.audioOnly.withHigestBitrate()

// ...or highest quality MP4 video-only stream
var streamInfo.videoOnly.where((e) => e.container == Container)

当我尝试使用此代码时,它说streamManifest 未定义名称,这是正确的,因为它未定义!。我试图通过声明streamManifest 来修复它,但没有用。任何人都可以检查这个,或者如果他们已经使用过这个包,那么请帮忙。一些好的帮助将不胜感激。

文档链接 - https://pub.dev/packages/youtube_explode_dart

【问题讨论】:

    标签: flutter dart youtube package flutter-packages


    【解决方案1】:

    如包文档中所述,您可以在 GitHub 上找到一个工作示例

     var yt = YoutubeExplode();
     var id = VideoId("https://youtu.be/cqY_tJfhKLw");//for example
     var video = await yt.videos.get(id);
     // Get the streams manifest and the audio track.
     var manifest = await yt.videos.streamsClient.getManifest(id);
     var audio = manifest.audioOnly.last;
    
                  
    

    【讨论】:

      【解决方案2】:

      这就是我使用 youtube_explore_dart 库的经验。 使用终端安装库的最后更新

      flutter pub add youtube_explode_dart
      

      那么,

      var _yt = YoutubeExplode();
      var manifest_ = await _yt.videos.streamsClient.get(_youtubeVideoId) // with _youtubeVideoId is the id of youtube video example LoSm6VkplJc
      var streamInfo = manifest.audioOnly
          .withHighestBitrate()
      

      这是为了获得具有最高音频质量的音频流。然后您可以使用 Its infos 和 streamsClient 下载该视频流,然后您可以将其流式传输到系统中的本地文件。

      if (streamInfo != null) {
          var stream = _yt.videos.streamsClient.get(streamInfo);
          _fileName = file.path; // this is path of Directory instance
          var fileStream = file.openWrite();
      
            // Pipe all the content of the stream into the file.
            try {
              await stream.pipe(fileStream).then((value) {
                return value;
              }).catchError((err) => error = err);
            } catch(err){
              error = err.toString();
            }
      
            // Close the file.
            await fileStream.flush();
            await fileStream.close();
      }
      

      【讨论】:

        猜你喜欢
        • 2019-12-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-02
        • 1970-01-01
        • 2021-08-12
        • 1970-01-01
        相关资源
        最近更新 更多