Programmerz
Programmerz

Reputation: 177

Undefined name streamManifest in youtube_explode_dart package flutter

I am having trouble with documentation of youtube_explode_dart package in flutter. I am trying to build a music streaming app using this package and firebase storage but their seems to be some mistake in the documentation code(code given below)

// 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)

When I try using this code it says streamManifest is not defined name which is correct because it is not defined!. I tried to fix it by declaring streamManifest but no use. Can anyone please check this or If they have already used this package then please help. Some good help will be really appreciated.

Link to the documentation - https://pub.dev/packages/youtube_explode_dart

Upvotes: 1

Views: 802

Answers (2)

Mouhsine Elachbi
Mouhsine Elachbi

Reputation: 41

This is what worked for my experience using youtube_explore_dart library. Install the last update of the library using terminal

flutter pub add youtube_explode_dart

Then,

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()

this is to get the audio stream with the highest audio quality. And Then you can download that video stream using Its infos and streamsClient and then you can stream It to a local file in your system.

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();
}

Upvotes: 0

AndroLogiciels
AndroLogiciels

Reputation: 196

As mentioned in the package documentation, you can find a working example on 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;

              

Upvotes: 3

Related Questions