JLT
JLT

Reputation: 3172

Playing m3u8 from Amazon S3 + CloudFront with Signed URL in Android

I was able to access the playlist file (.m3u8) with signed URL. But the problem is, to access the stream files (.ts) within the playlist, the URL of each file needs to be signed too.

For Example:

I can access playlist.m3u8 with signed URL http://abcdefg.cloudfront.net/media/playlist.m3u8?Expires=xxxxxxxx&Policy=yyyyyyyyyyyyy&Signature=zzzzzzzzzzzzzz&Key-Pair-Id=kkkkkkkkkkkkkkkkk

#EXTM3U
#EXT-X-TARGETDURATION:10
#EXTINF:13
playlist-00000.ts
#EXTINF:12,
playlist-00001.ts
#EXTINF:12,
playlist-00002.ts

But each ts file inside it should also be accessed like

http://abcdefg.cloudfront.net/media/playlist-00000.ts?Expires=xxxxxxxx&Policy=yyyyyyyyyyyyy&Signature=zzzzzzzzzzzzzz&Key-Pair-Id=kkkkkkkkkkkkkkkkk

I have to sign every single URL for each .ts files in the playlist.

Unfortunately, I don't see any media player that could handle the appending of the parameters for the URL before it gets the ts files.

If possible, I need a callback from the player like this:

public String onStreamFileReadyForPlaying(String pathToTsFile)
{
     //I could append the parameters here
     return pathToTsFile + "?Expires=xxxxxxxx&Policy=yyyyyyyyyyyyy&Signature=zzzzzzzzzzzzzz&Key-Pair-Id=kkkkkkkkkkkkkkkkk"
}

Upvotes: 6

Views: 6403

Answers (3)

Jijo
Jijo

Reputation: 157

You can use cloudfront signed urls with custom to allow access to all files inside a folder with a single singature.

AWS Documentation

For that you have generate a cloudfront keypair. To generate go to my security credentials in the top drop down and select cloufront. There you can see the option to generate key pair.

Upvotes: 0

Changwoo Rhee
Changwoo Rhee

Reputation: 181

There is two way of "Using Signed URLs" and "Signed Cookies"

I think that you have to use "Signed Cookies"

I found below of link why use "Signed Cookies" https://docs.amazonaws.cn/en_us/AmazonCloudFront/latest/DeveloperGuide/private-content-choosing-signed-urls-cookies.html

Use signed cookies in the following cases:

  • You want to provide access to multiple restricted files, for example, all of the files for a video in HLS format or all of the files in the subscribers' area of website.

I didn't try "Signed Cookies" yet. but i have same problem. if you have been done "Signed Cookies" Can you give feedback?

below of link is document of how to use "Sigend Cookies" https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-signed-cookies.html

Upvotes: 1

Brad
Brad

Reputation: 163234

Simply sign the URLs in the playlist.

That's all there is to it.

Upvotes: 3

Related Questions