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

AudioSource.uri does not set dynamically headers #1272

Open
GoranSustekJr opened this issue Jun 25, 2024 · 1 comment
Open

AudioSource.uri does not set dynamically headers #1272

GoranSustekJr opened this issue Jun 25, 2024 · 1 comment
Assignees
Labels
1 backlog bug Something isn't working

Comments

@GoranSustekJr
Copy link

GoranSustekJr commented Jun 25, 2024

Which API doesn't behave as documented, and how does it misbehave?
When Creating a type List, I dynamically trough for loop create AudioSource.uri with headers and add it to the list.

Minimal reproduction project
Provide a link here using one of two options:
Will provide if needed.

To Reproduce (i.e. user steps, not code)
Steps to reproduce the behavior:
Will provide if needed
Error messages

If applicable, copy & paste error message here, within the triple quotes to preserve formatting.

Expected behavior
I expect to hear three different audios, but I hear only one three times.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

  • Device: Samsung Galaxy A22
  • OS: Android 13

Flutter SDK version

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.22.2, on Ubuntu 24.04 LTS 6.8.0-35-generic, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2023.3)
[✓] VS Code (version 1.90.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

Additional context
I have a videoIds list which contains some strings. Then I iterate trough a for loop which takes every videoId from videoIds list. It creates new AudioSource.uri() with custom headers and tagItem. After that it adds it to sources list type List. After the loop finishes I return the sources list. The Player does make three connections, which is the length of videoIds list and when I look at background audio played, info is correct, but it plays the same song three times. I also see on my server that headers gotten from all three requests have same headers videoId. The printed out headers when setting AudioSource from uri are correct (can be seen in code)

Code

initializePlayer() async {
    setState(() {
      playlist = ConcatenatingAudioSource(
          children:
              dynamicSongs(),
          useLazyPreparation: true);
    });

    await player.setAudioSource(playlist,
        initialIndex: 0, initialPosition: Duration.zero);
  }

dynamicSongs() {
    List<AudioSource> children = [];
    for (int h = 0; h < videoIds.length; h++) {
      print("VIDEOID: $videoIds ${videoIds[h]}");

      AudioSource source = AudioSource.uri(
          Uri.parse("https://goransustekdoo.ddns.net:5002/play_song"),
          headers: {'VideoId': videoIds[h], "Connection": "Keep-Alive"},
          tag: MediaItem(id: videoIds[h], title: videoIds[h]));

     print(sources);
      print(AudioSource.uri(
              Uri.parse("https://goransustekdoo.ddns.net:5002/play_song"),
              headers: {'VideoId': videoIds[h], "Connection": "Keep-Alive"},
              tag: MediaItem(id: videoIds[h], title: videoIds[h]))
          .headers);
      print("HHDJAHFJDAHFJDAHFJDAHFJDAHFJDA");
      children.add(source);
    }

  
    return children;
  }

Flutter debug console output

VIDEOID: [vE68EvHbLwU, iTjfR9q5RO8, GrwRMSozywg] vE68EvHbLwU
I/flutter (32646): Instance of 'ProgressiveAudioSource'
I/flutter (32646): {VideoId: vE68EvHbLwU, Connection: Keep-Alive}
I/flutter (32646): HHDJAHFJDAHFJDAHFJDAHFJDAHFJDA
I/flutter (32646): VIDEOID: [vE68EvHbLwU, iTjfR9q5RO8, GrwRMSozywg] iTjfR9q5RO8
I/flutter (32646): Instance of 'ProgressiveAudioSource'
I/flutter (32646): {VideoId: iTjfR9q5RO8, Connection: Keep-Alive}
I/flutter (32646): HHDJAHFJDAHFJDAHFJDAHFJDAHFJDA
I/flutter (32646): VIDEOID: [vE68EvHbLwU, iTjfR9q5RO8, GrwRMSozywg] GrwRMSozywg
I/flutter (32646): Instance of 'ProgressiveAudioSource'
I/flutter (32646): {VideoId: GrwRMSozywg, Connection: Keep-Alive}
I/flutter (32646): HHDJAHFJDAHFJDAHFJDAHFJDAHFJDA

Python API Output

Headers({'host': 'goransustekdoo.ddns.net:5002', 'x-real-ip': '195.29.146.158', 'x-forwarded-for': '195.29.146.158', 'x-forwarded-proto': 'https', 'connection': 'Keep-Alive', 'user-agent': 'Mozilla/', 'videoid': 'GrwRMSozywg', 'accept-encoding': 'identity', 'icy-metadata': '1'})
RETURNING
INFO:     goransustekdoo.ddns.net:5002 - "GET /play_song HTTP/1.0" 200 OK
Headers({'host': 'goransustekdoo.ddns.net:5002', 'x-real-ip': '195.29.146.158', 'x-forwarded-for': '195.29.146.158', 'x-forwarded-proto': 'https', 'connection': 'Keep-Alive', 'user-agent': 'Mozilla/', 'videoid': 'GrwRMSozywg', 'accept-encoding': 'identity', 'icy-metadata': '1'})
RETURNING
INFO:     goransustekdoo.ddns.net:5002 - "GET /play_song HTTP/1.0" 200 OK
Headers({'host': 'goransustekdoo.ddns.net:5002', 'x-real-ip': '195.29.146.158', 'x-forwarded-for': '195.29.146.158', 'x-forwarded-proto': 'https', 'connection': 'Keep-Alive', 'user-agent': 'Mozilla/', 'videoid': 'GrwRMSozywg', 'accept-encoding': 'identity', 'icy-metadata': '1'})
RETURNING
INFO:     goransustekdoo.ddns.net:5002 - "GET /play_song HTTP/1.0" 200 OK

If anything else is needed, please say

@GoranSustekJr GoranSustekJr added 1 backlog bug Something isn't working labels Jun 25, 2024
@GoranSustekJr GoranSustekJr changed the title AudioSource.uri does not set dynamically haeders AudioSource.uri does not set dynamically headers Jun 25, 2024
@GoranSustekJr
Copy link
Author

Okay, after a lot of debugging the issue was with ConcatenatingAudioSource. AudioSources that it consists of are from uri. Url is the same but headers are different. It seems that just_audio for same url uses same headers. The solution is to use query parameters in url instead of headers. It would be nice if you could fix it and/or add support for different headers if someone will be sending data about song being played in them and add body support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants