Hi, I´m not able to get AES to work on iPhone. But its working on windows
I found this issue here that talks about creating a proxy (?) to solve the known issue in Azure Media Player
AES and restricted token content does not playback using iOS and older Android devices. In order to achieve this scenario, a proxy must be added to your service.
What is it I have to do?
My setup is:
Razor page that gets the url with token
private async Task GetStreamEventsAsync(Guid eventPageId)
{
var @event = await StreamEventsAppService.GetVideoWithUrlsAndTokenAsync(eventPageId);
LiveStreamUrl = @event.HlsUrl;
Token = $"Bearer={@event.Token}";
}
the controller
[HttpGet]
[Route("live-stream-video-token")]
public virtual Task<VideoDto> GetVideoWithUrlsAndTokenAsync(Guid eventPageId)
{
return _streamEventsAppService.GetVideoWithUrlsAndTokenAsync(eventPageId);
}
With this to display it
<video id="azuremediaplayer" class="azuremediaplayer amp-default-skin amp-big-play-centered"> </video>
<script>
var myOptions = {
autoplay: true,
controls: true,
width: "100%",
height: "800",
poster: "",
"logo": { "enabled": false },
};
var myPlayer = amp("azuremediaplayer", myOptions);
myPlayer.src([{ src: "@Model.LiveStreamUrl", type: "application/vnd.ms-sstr+xml", protectionInfo: [{ type: "AES", authenticationToken: "@Model.Token" }]}]);
</script>
p.s
Just found this example https://github.com/AzureMediaServicesSamples/HLSSafariProxy and will try to figure it out and see if I can´t adopt that code.
UPDATE 1 :
With using this demo site https://mingfeiy.azurewebsites.net/ I was able to paste in the manifest url and my token and play this on my iPhone. So Now I just have to figure out the code and get to to work with mine
Since this was old code I had to update it like this
[HttpGet]
[Route("proxy")]
public virtual async Task<HttpResponseMessage> GetProxyAsync(string playbackUrl, string token)
{
var collection = HttpUtility.ParseQueryString(token);
var authToken = collection.ToQueryString();
string armoredAuthToken = HttpUtility.UrlEncode(authToken);
var httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromSeconds(30);
var response = new HttpResponseMessage();
try
{
var stream = await httpClient.GetStreamAsync(playbackUrl);
if (stream != null)
{
using (var reader = new StreamReader(stream))
{
const string qualityLevelRegex = @"(QualityLevels\(\d+\))";
const string fragmentsRegex = @"(Fragments\([\w\d=-]+,[\w\d=-]+\))";
const string urlRegex = @"("")(https?:\/\/[\da-z\.-]+\.[a-z\.]{2,6}[\/\w \.-]*\/?[\?&][^&=]+=[^&=#]*)("")";
var baseUrl = playbackUrl.Substring(0, playbackUrl.IndexOf(".ism", System.StringComparison.OrdinalIgnoreCase)) + ".ism";
var content = reader.ReadToEnd();
var newContent = Regex.Replace(content, urlRegex, string.Format(CultureInfo.InvariantCulture, "$1$2&token={0}$3", armoredAuthToken));
var match = Regex.Match(playbackUrl, qualityLevelRegex);
if (match.Success)
{
var qualityLevel = match.Groups[0].Value;
newContent = Regex.Replace(newContent, fragmentsRegex, m => string.Format(CultureInfo.InvariantCulture, baseUrl + "/" + qualityLevel + "/" + m.Value));
}
response.Content = new StringContent(newContent, Encoding.UTF8, "application/vnd.apple.mpegurl");
}
}
}
catch (Exception ex)
{
}
finally
{
httpClient.Dispose();
}
return response;
}
That returns the following (I hope its correct) and then I´ll work on stitching it together tomorrow
{
"version": "1.1",
"content": {
"headers": [
{
"key": "Content-Type",
"value": [
"application/vnd.apple.mpegurl; charset=utf-8"
]
}
]
},
"statusCode": 200,
"reasonPhrase": "OK",
"headers": [],
"trailingHeaders": [],
"requestMessage": null,
"isSuccessStatusCode": true
}
UPDATE 2
Since I had problems updating the code above to work with modern .net I searched the internet and found these sources.
- HLSSafariProxy the original code (as above)
- AmsHLSProxy based on the original but for 2017 style Azure functions
- HLS proxy example I found
- HLS Proxy service for AES encrypted HLS stream This is the newest one (last updated 2020)