video_player_web_hls icon indicating copy to clipboard operation
video_player_web_hls copied to clipboard

Unable to read m3u8 file from AWS Cloudfront (using AWS Signed URL technology)

Open vanderke opened this issue 11 months ago • 4 comments

I've got several audio and video files in an S3 bucket serviced by Cloudfront. I'm sure that the .m3u8 files are valid, as I can get access to them if I use a signed url. However, I can't seem to get the headers to get passed in the subsequent calls. Here's the code snippet that I'm using (taken string from the initState() method in the sample code):

    String url = "https://cdn.example.com/folder1/folder2/folder3/myMovie.m3u8";
    Map<String, String> httpHeaders = {
      "useCookies": "true",
      "CloudFront-Policy": "${AWSCloudFrontSignedUrl.cloudFrontPolicy}",
      "CloudFront-Signature": "${AWSCloudFrontSignedUrl.cloudFrontSignature}",
      "CloudFront-Key-Pair-Id": "${AWSCloudFrontSignedUrl.cloudFrontKeyPairId}",
    };
    _controller = VideoPlayerController.networkUrl(Uri.parse(url), httpHeaders: httpHeaders)
      ..initialize().then((_) {
        // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
        setState(() {});
      });

When the player is trying to intialize, I see that some of the URLs have the correct URL on them, but some do not. image This is done in the same network call, but without all of the signature stuff added to it: image I'm not sure how to get the player to add the extra parameters to each and every item that is in the playlist. Thanks for your help!

vanderke avatar Mar 08 '24 19:03 vanderke

There does seem to be a way to do this transparently using this article from AWS and having 2 different cloudfronts going on. So I don't think that this is going to stop me from using this, however, there still seems to be an issue with using the cookies passed in through the header consistently.

vanderke avatar Mar 11 '24 17:03 vanderke

Did you ever find a satisfactory resolution to this?

Adam

aviettran avatar Jul 07 '24 13:07 aviettran

Hey Adam, Unfortunately, no. The article from AWS that I linked to was more "sample code" rather than fully tested code, and as a result, it didn't work as advertised. We're still working through the AWS configuration to see if we can get it to work, but so far, it's still not working.

vanderke avatar Jul 17 '24 17:07 vanderke

Okay. If your organization wants to write me up an hourly contract, I'd love to take a look. This type of thing genuinely interests me so I'm willing to tackle it if you need help.

aviettran avatar Jul 17 '24 19:07 aviettran