-
-
Notifications
You must be signed in to change notification settings - Fork 694
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
Feature request: lazy fetching of audio URLs in ConcatenatingAudioSource #777
Comments
Maybe it could be called I do wonder, what should this new audio source do if the mapping function rotated its URLs during a range request? i.e. the player requests the resource from the beginning, then the URL expires and gets rotated, then the player continues its thing making a range request for the end of the file without realising that a different resource is now being returned. |
In my case, the URL won't expire if it's in use, so this isn't an issue. I was thinking more along the lines of the URL being cached, but I suppose that could always be implemented outside of I think a decent backend should still support any range request just fine, though - it is serving the same file, after all.
I meant "lazy" as in the URL is loaded lazily when it is needed by the plugin, but that's a good point. |
On another note, this concept could be extended to allow postponed generation of any |
From the platform player's perspective, each audio source is a URI. In the case of a This is no problem in your use case if each time the origin URL rotates out, the new origin URL still effectively refers to the very same resource. But this API could easily be misused by someone who thinks it would be a good idea to make it return a randomised song each request, like a jukebox. In that case, the platform player will be sending multiple range requests to fetch different parts of what it assumes is the same file, but if the mapping changes in the middle of doing that, then the platform player will fetch the head of one song and the tail of another song, and the decoder won't know how to decode what results. I suppose this is fine so long as the documentation states clearly that the origin URI returned by this mapping function must always effectively point to the same resource. That is, even though the URI returned may be different each time, the actual data response should be stable. |
In terms of implementing this: I've been looking into where to store the
Do you have any ideas on how to solve this problem? My initial thought is to have each platform report when its finished with an |
Perhaps these should be deallocated on |
Any progress or plans on implementing this? |
There are two pull requests available now to try (#779 and #800), but I'm thinking of a 3rd approach that might be a better approach long term. For now, you will need to pick one of the available pull requests, noting that the first one is implemented precisely in native code and may not work on all platforms, while the second one is implemented approximately in Dart and should be cross platform. |
@ryanheise Thank you for pointing out to ResolvingAudioSource #800. |
Hi @ryanheise , I have exactly the same use case: my audio files come from an URI that must be resolved just before playing them. They are signed and, for security reasons, I have to keep the validity window as small as possible. The #800 does what I need. I've noticed that it's waiting to be merged since Sept. 2022, is there a particular reason? Can I do anything to make it advance? Thanks again for your awesome work, just_audio works so well! |
Hi @synapticvoid you can see #779 for a discussion of the various approaches. I'm not able to commit to one direction or the other at this time since I think the ideal solution would also involve a new platform architecture. However, the solution you linked to is possible to implement without direct support inside the plug-in because it is just a subclass of stream audio source. |
Thanks for your quick response. I read the #779, and you're right, there are deeper consequences for this feature. Unfortunately, I cannot use the #800 solution, as it involves redefining internal methods, specifically: @override
AudioSourceMessage _toMessage() {
return ProgressiveAudioSourceMessage(
id: _id, uri: _uri.toString(), headers: headers, tag: tag);
}
|
Why do you need |
In my custom |
That is not one of the viable solutions that were offered to you above. |
Oh I see. I'll try it out to see how it works. Thanks again for your quick responses! |
Is there a way to modify the AudioSource Uri of the index specified in the ConcatenatingAudioSource so that I can update the Uri of the next song by listening to the _player.currentIndex to achieve laziness to get the music link. I tried to remove and then insert, but this resulted in an Index Error (tested in Android)and then infinite seek to the next music. |
You could probably append the updated AudioSource behind the next source, and then remove the original next source. To visualize:
That might work without resulting in index errors? |
Is your feature request related to a problem? Please describe.
The audio URLs provided by the API I'm using expire after a fairly short amount of time. The API provides a "queue" in the form of a list of identifier keys, and then the audio URL can be requested for playback using the identifier.
It'd be great to have a way to use the "queue" with a
ConcatenatingAudioSource
, taking advantage of its preloading capabilities (as well as the ability to tightly couple theConcatenatingAudioSource
withaudio_service
and only manage one queue).Describe the solution you'd like
A lambda based API would work nicely here.
When the audio source is played (or preloaded),
fetchUri
is called beforehand. This process is invisible to the end user, to whom it appears as if the regular audio file is buffering.Describe alternatives you've considered
This could be implemented through
StreamAudioResponse
, but it would be a lot easier not to have to implement the network I/O manually, and probably more performant to let the platform handle it as (I believe?)UriAudioSource
does now.The
ConcatenatingAudioSource
could also just be avoided for this use case, but that's disappointing for the reasons I mention above.Additional context
I'm happy to take a crack at implementing this myself if you'd be willing to include this feature.
The text was updated successfully, but these errors were encountered: