Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Youtube Api queue problem #818

Closed
cometothed4rkside opened this issue Sep 16, 2022 · 12 comments
Closed

Youtube Api queue problem #818

cometothed4rkside opened this issue Sep 16, 2022 · 12 comments
Assignees
Labels
1 backlog bug Something isn't working

Comments

@cometothed4rkside
Copy link

Is your feature request related to a problem? Please describe.
Hi first of all thanks for this great library. When I create a playlist, it sends requests to all youtube links at once. And this causes the user to spend a lot of internet. I want to create a playlist and when it's time for the song, I want to send a request to the youtube api and get the url of that song. I don't want to send requests to all of them when the playlist creates. I will be grateful if you could help me.

My youtube api code:
Future getSongUrl(songId) async {
var yt = YoutubeExplode();
final manifest = await yt.videos.streamsClient.getManifest(songId);
return manifest.audioOnly[1].url.toString();
}

Describe the solution you'd like
Retrieving links from the api when the song is playing.

Additional context
https://pub.dev/packages/youtube_explode_dart

@ryanheise
Copy link
Owner

ConcatenatingAudioSource(useLazyPreparation: true) is intended for this purpose although isn't implemented for iOS yet.

However, you can try the feature/treadmill branch to see if it improves for you. Also, DarwinLoadControl(preferredForwardBufferDuration: ...) should help, but reports are that this iOS option doesn't actually have any effect (unfortunately).

@ryanheise
Copy link
Owner

Related to #294 .

@cometothed4rkside
Copy link
Author

cometothed4rkside commented Sep 16, 2022

I added the feature/treadmill feature, but they all send requests to the api at the same time. This is my code:

final _playlist = ConcatenatingAudioSource(
useLazyPreparation: true
      children: [
        getMusicVideos("LkzUf7cKLNA"),
        getMusicVideos("LkzUf7cKLNA"),
        getMusicVideos("LkzUf7cKLNA"),
        getMusicVideos("LkzUf7cKLNA"),
        getMusicVideos("LkzUf7cKLNA"),
  ]);

 getMusicVideos(songId) {
  print("dasdasdasdas");
  return AudioSource.uri(
    Uri.parse(""),
    tag: AudioMetadata(
      album: "Science Friday",
      title: "A Salute To Head-Scratching Science",
      artwork:
      "https://media.wnyc.org/i/1400/1400/l/80/1/ScienceFriday_WNYCStudios_1400.jpg",
    ),
  );
}

@ryanheise
Copy link
Owner

I'm not sure how that is possible given that feature/treadmill does not even add all of the items to the playback queue. It is impossible for them to all be loaded at the same time. I am guessing that you are not actually using the branch?

@cometothed4rkside
Copy link
Author

cometothed4rkside commented Sep 16, 2022

Yes, I added that feature/treadmill. When I add song from my own server as a url, I see that there are 2 requests to my server. But when I want to add the url returned in the getMusicVideos function instead of a my server url, it works 5 times and output dasdasdasdas 5 times.

getMusicVideos(songId) {
 print("dasdasdasdas");
 return AudioSource.uri(
   Uri.parse(""),
   tag: AudioMetadata(
     album: "Science Friday",
     title: "A Salute To Head-Scratching Science",
     artwork:
     "https://media.wnyc.org/i/1400/1400/l/80/1/ScienceFriday_WNYCStudios_1400.jpg",
   ),
 );
}

@ryanheise
Copy link
Owner

Do you care about how many times that message prints, or do you care about how many times a request is made to the server? The prints have nothing to do with the requests.

@cometothed4rkside
Copy link
Author

The problem is that we don't know the music links at start. While creating the list, we need to send the music link. Uri.parse(""), But we don't have the link. For this, we use a function and request the link of the video from youtube. What we want to do is to get this link only when it's time for that song.

I tried the code you mentioned on iOS, but still, all elements send requests to youtube at the same time while creating a list.
We want the getMusicVideo function to run for each element in its turn.

Sorry maybe I am doing it wrong. The codes I use are can you check please?

Future<String> getMusicVideo(songId) async {
  final manifest = await yt.videos.streamsClient.getManifest(songId);
  print(manifest.muxed.last.url.toString());
  return manifest.muxed.last.url.toString();
}

UriAudioSource _createAudioSource(songId)  {
  String link = "";
  getMusicVideo(songId).then((value) {
   link = value;
  });
  return AudioSource.uri(
    Uri.parse(link),
    tag: AudioMetadata(
      album: "Science Friday",
      title: "A Salute To Head-Scratching Science",
      artwork:
      "https://media.wnyc.org/i/1400/1400/l/80/1/ScienceFriday_WNYCStudios_1400.jpg",
    ),
  );
}

  final _playlist = ConcatenatingAudioSource(
      useLazyPreparation: true,
      children: []);

  final mappingAudioSources = [
    _createAudioSource("ttPclYviWso"),
    _createAudioSource("iCDEB1NW-RY"),
    _createAudioSource("ZYYKHXqGgZg"),
  ];
  _playlist.addAll(mappingAudioSources);

@ryanheise
Copy link
Owner

OK, I think I understand your feature request now. Is it a duplicate of #777 ?

@cometothed4rkside
Copy link
Author

Yes we need #779 feature to iOS.

@ryanheise
Copy link
Owner

OK, it's a duplicate. I'll close this issue, and please follow #777 instead.

@ryanheise
Copy link
Owner

Duplicate of #777

@ryanheise ryanheise marked this as a duplicate of #777 Sep 16, 2022
@github-actions
Copy link

github-actions bot commented Oct 1, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with just_audio.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants