just_audio icon indicating copy to clipboard operation
just_audio copied to clipboard

[WEB] Dynamic headers for HLS player and Amazon S3

Open BartusZak opened this issue 3 years ago • 9 comments

Is your feature request related to a problem? Please describe. I use Amazon S3 (secured) to store my HLS files (.m3u8/ .aac). just_audio allows only to provide one, the same header for all files underneath.

Describe the solution you'd like Implement dynamic headers per .aac file with sigV4 headers (different header per .aac file)

Describe alternatives you've considered Use Amazon Signed Url

Additional context https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-signed-urls.html#private-content-overview-choosing-duration

BartusZak avatar Feb 17 '21 11:02 BartusZak

Hi @BartusZak

That link didn't specifically talk about HLS, so would you be able to point me to something HLS specific? Is it a feature of another HLS player that you can point me to?

If not, can you propose an API design that would satisfy your use case?

ryanheise avatar Feb 17 '21 12:02 ryanheise

Hey @ryanheise,

Thanks for very fast response.

I will prepare a design and get back to you.

BartusZak avatar Feb 17 '21 13:02 BartusZak

One concern I have is if no existing audio player library supports this, then it may not be feasible. just_audio is built upon lower level audio player APIs and those themselves need to be able to support this if just_audio is to. The underlying player engine on the platform side takes over complete control of HLS loading with no way to control it. One exception being certain DRM standards.

ryanheise avatar Feb 17 '21 13:02 ryanheise

Any update on this?

ryanheise avatar Mar 14 '21 04:03 ryanheise

What do you use as HLS server? Does aws provide a HLS server to stream music?

alexgrusu avatar Mar 26 '21 15:03 alexgrusu

@alexgrusu

As a POC I created .aac and .m3u8 files with AWS Elemental MediaConvert from a few .mp3 files.

Then I uploaded them to Private Amazon S3 Bucket. Now I am trying to receive them from Flutter WEB .

There is more services you can look at: image

@ryanheise I described the way I construct Signed Request Headers for Amazon S3 (https://github.com/ryanheise/just_audio/issues/304#issuecomment-815624048).

The entry point for inserting source audio is like follows:


    _playlist = ConcatenatingAudioSource(
        children: await Future.wait(widget.audiobook!.content!
            .map(
              (content) async => AudioSource.uri(
                  Uri.parse(widget.audiobook!.url! + content!.file!),
                  headers: await _s3Repository!.generateSignedHeaders(
                      widget.audiobook!.url! + content.file!),
                  tag: AudioMetadata(
                      title: content.title, artwork: widget.audiobook!.cover)),
            )
            .toList()));

I uses SigV4 package to calculate headers but there is a official package from AWS team https://github.com/aws-amplify/amplify-flutter.

There is an IF statement to handle .m3u8 already, so there is no sense to create another API. Request Headers and HLS support for web is needed for my case.

BartusZak avatar Apr 08 '21 11:04 BartusZak

Hey @ryanheise How are you?

Is there any chance to get request headers working on WEB?

BartusZak avatar Jul 17 '21 15:07 BartusZak

My need seems to overlap if not be the same. I am using signed URLs with Amazon Cloudfront to serve HLS audio. I already have a method for obtaining the signature, but It requires that "the video [or audio] player will need to be modified to append the signature to every request for a fragment."

Eg. "https://xyz.cloudfront.net/fragement.aac?Policy=SIGNEDURL"

for example with videoJs:

videojs.Hls.xhr.beforeRequest = function (options) {
      options.uri = `${options.uri}${videojs.getAllPlayers()[0].options().token}`;
      return options;
};

Is this possible with just_audio?

djsjr avatar Jul 26 '21 17:07 djsjr

@djsjr if it's not the same feature, I'd suggest you open a separate feature request. The present issue is about headers.

ryanheise avatar Jul 27 '21 01:07 ryanheise