3

I am streaming files with a CloudFront web distribution on top of a S3 storage containing private files (CloudFront has access to it). I use AWS WAF to validate if the request comes from my domain (with the referer header) to avoid direct download of the audio file with a simple copy-paste of its URL. To play the audio files, I use SoundManager2.

The problem: it works like a charm on desktop browsers (Chrome, Firefox and Safari), but the stream never start playing on mobile (tested on iOs and Android). I can't get why.

**General**
Request URL:https://XXXXXXXXX.cloudfront.net/uploads/track/s3_file/XXXXX/XXXXXXXXXXXX.mp3
Request Method:GET
Status Code:206 Partial Content
Remote Address:XX.XX.XXX.X:XXX

**Response Headers**
Accept-Ranges:bytes
Age:9230
Cache-Control:max-age=31536000
Connection:keep-alive
Content-Length:2
Content-Range:bytes 0-1/4958188
Content-Type:audio/mp3
Date:Wed, 20 Apr 2016 11:35:09 GMT
ETag:"3f90ed8fa62501906107380830996ae9"
Last-Modified:Mon, 18 Apr 2016 15:05:16 GMT
Server:AmazonS3
Via:1.1 70801f007508df9ad04c63e7be99eab2.cloudfront.net (CloudFront)
X-Amz-Cf-Id:e-MSj2EuajyCKG8ah8f5WzjqQxymLfCeGaH5q6AMgt7T42u7wFKGig==
X-Cache:Hit from cloudfront

**Request Headers**
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8,fr;q=0.6
Cache-Control:no-cache
Connection:keep-alive
Host:XXXXXXXXXX.cloudfront.net
Pragma:no-cache
Range:bytes=0-1
Referer:http://www.domain.com/this-is-a-playlist/other-lives-tamer-animals
Save-Data:on
User-Agent:Mozilla/5.0 (Linux; Android 5.1.1; A0001 Build/LMY48Y) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.105 Mobile Safari/537.36

On the web version, SoundManager2 sends this first request and cancel it:

**General**
Request URL:https://XXXXXXXX.cloudfront.net/uploads/track/s3_file/XXX/XXXXXXXXXXXXX.mp3

**Request Headers**
Provisional headers are shown
Accept-Encoding:identity;q=1, *;q=0
Range:bytes=0-
Referer:http://www.domain.com/this-is-a-playlist/other-lives-tamer-animals
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36

Then this request goes right after the above:

**General**
Request URL:https://XXXXXXXXXXX.cloudfront.net/uploads/track/s3_file/XXX/XXXXXXXXXX.mp3
Request Method:GET
Status Code:206 Partial Content
Remote Address:XX.XX.XXX.XXX:XXX

**Response Headers**
view source
Accept-Ranges:bytes
Age:168539
Cache-Control:max-age=31536000
Connection:keep-alive
Content-Length:4958188
Content-Range:bytes 0-4958187/4958188
Content-Type:audio/mp3
Date:Mon, 18 Apr 2016 15:35:12 GMT
ETag:"3f90ed8fa62501906107380830996ae9"
Last-Modified:Mon, 18 Apr 2016 15:05:16 GMT
Server:AmazonS3
Via:1.1 c035b03e455c334ee837503784ad41c8.cloudfront.net (CloudFront)
X-Amz-Cf-Id:bE3BNkkvWJ08qwcsRT-3TIvHs6dXT-QIJ8UP6kl3vQVg89LaiO1Npg==
X-Cache:Hit from cloudfront

**Request Headers**
view source
Accept:*/*
Accept-Encoding:identity;q=1, *;q=0
Accept-Language:fr,en-US;q=0.8,en;q=0.6
Cache-Control:no-cache
Connection:keep-alive
Host:XXXXXXXXXXX.cloudfront.net
Pragma:no-cache
Range:bytes=0-
Referer:http://www.domain.com/this-is-a-playlist/other-lives-tamer-animals
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36

On mobile, SoundManager2 reaches the playing status in the logs, but now music is played. Do anyone get why the stream doesn't start on mobile???

ocolot
  • 718
  • 6
  • 18

1 Answers1

0

On Windows Mobile this would work.
See explanation about WAF and HTML5 audio/video on some mobile browsers here:
Preventing Amazon Cloudfront hotlinking

Community
  • 1
  • 1
figolu
  • 1,388
  • 13
  • 6
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Please [add context around the link](http://meta.stackoverflow.com/a/8259/169503) so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. – Ingo Karkat Sep 22 '16 at 12:11