-
-
Notifications
You must be signed in to change notification settings - Fork 689
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
Dynamic header generation with AudioSource.uri
#967
Labels
Comments
I'm sorry, this may me the duplicate of #777 |
after watching #800, this code works on branch import 'dart:async';
import 'dart:io';
import 'package:just_audio/just_audio.dart';
import 'package:just_audio_platform_interface/just_audio_platform_interface.dart'
show AudioSourceMessage, ProgressiveAudioSourceMessage;
class ResolvingAudioSource extends StreamAudioSource {
final String uniqueId;
final Uri url;
final Map<String, String> Function() headersCreater;
HttpClient? _httpClient;
HttpClient get httpClient => _httpClient ?? (_httpClient = HttpClient());
ResolvingAudioSource(
{required this.uniqueId,
required this.url,
required this.headersCreater,
dynamic tag})
: super(tag: tag);
@override
Future<StreamAudioResponse> request([int? start, int? end]) async {
final request = await httpClient.getUrl(url);
for (var entry in headersCreater().entries) {
request.headers.set(entry.key, entry.value);
}
if (start != null || end != null) {
request.headers
.set(HttpHeaders.rangeHeader, 'bytes=${start ?? ""}-${end ?? ""}');
}
final response = await request.close();
final acceptRangesHeader =
response.headers.value(HttpHeaders.acceptRangesHeader);
final contentRange = response.headers.value(HttpHeaders.contentRangeHeader);
int? offset;
if (contentRange != null) {
int offsetEnd = contentRange.indexOf('-');
if (offsetEnd >= 6) {
offset = int.tryParse(contentRange.substring(6, offsetEnd));
}
}
final contentLength =
response.headers.value(HttpHeaders.contentLengthHeader);
final contentType = response.headers.value(HttpHeaders.contentTypeHeader);
return StreamAudioResponse(
rangeRequestsSupported:
acceptRangesHeader != null && acceptRangesHeader != 'none',
sourceLength: null,
contentLength:
contentLength == null ? null : int.tryParse(contentLength),
offset: offset,
stream: response.asBroadcastStream(),
contentType: contentType ?? "");
}
@override
AudioSourceMessage _toMessage() {
return ProgressiveAudioSourceMessage(
id: uniqueId, uri: url.toString(), headers: headersCreater(), tag: tag);
}
} |
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. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
maybe related
Is your feature request related to a problem? Please describe.
I'm trying to play some online music that needs custom header that includes "Request Timestamp" and "Signature created with Timestamp and access/secret key"(just like this implementation).
When I try to play single song with
setUrl
likeAudioPlayer.setUrl(url, headers: generateSignedHeaders(url))
, works pretty good.But if I set playlist as a audio source, latter music's header will be expired and unable to listen. Off course, if I play back to the first track of the playlist from second one, It's already expired.
Describe the solution you'd like
I'd love to have an argument which evaluate header just the time loading starting like below
Describe alternatives you've considered
Or, custom subclass of Playlist can be great like
Additional context
Add any other context or screenshots about the feature request here.
Thanks for such a great plugin. I hope this Feature request will be accepted soon and bring a nice change to this plugin.
The text was updated successfully, but these errors were encountered: