Liidia
Liidia

Reputation: 65

Where the segments listed in a HLS playlist are located?

I have the next HLS playlist: https://digitacdn.akamaized.net/hls/live/629243/radiosuomipop/master-128000.m3u8. It contains AAC audio file segments links. File content is:

#EXTM3U
#EXT-X-VERSION:3
## Created with Z/IPStream R/2 v1.03.23
#EXT-X-MEDIA-SEQUENCE:2984548
#EXT-X-TARGETDURATION:6
#EXT-X-PROGRAM-DATE-TIME:2018-10-23T11:44:44Z
#EXTINF:5.99, no desc
01493/seg128000-02984548.aac
#EXTINF:5.99, no desc
01493/seg128000-02984549.aac
#EXTINF:5.99, no desc
01493/seg128000-02984550.aac
#EXTINF:5.99, no desc
01493/seg128000-02984551.aac
#EXTINF:5.99, no desc
01493/seg128000-02984552.aac
#EXTINF:5.99, no desc
01493/seg128000-02984553.aac

I can not understand where these segments are located. Could anybody explain me that? How can I reach each separate segment to play it, for instance, with NAudio MediaFoundationReader?

Upvotes: 1

Views: 1618

Answers (1)

spender
spender

Reputation: 120400

Due to the lack of leading /, the resources exist at a location relative to the source document in exactly the same way as links in HTML pages work. So: for instance 01593/seg128000-03184874.aac found in the document at https://digitacdn.akamaized.net/hls/live/629243/radiosuomipop/master-128000.m3u8 exists at https://digitacdn.akamaized.net/hls/live/629243/radiosuomipop/01593/seg128000-03184874.aac.

A safe way of dealing with this is to use existing overloads on the Uri class:

var m3u8Url = 
  "https://digitacdn.akamaized.net/hls/live/629243/radiosuomipop/master-128000.m3u8"
var baseUri = new Uri(m3u8Url);
var resourceUri = new Uri(baseUri, "01493/seg128000-02984548.aac");
Console.WriteLine(resourceUri.AbsoluteUri);

Done this way, the resulting Urls will be assembled using the same logic as used by browsers, correctly dealing with relative (32724/foo), local absolute (/32724/foo) and fully qualified URLs (http://somehost/32724/foo).

Upvotes: 2

Related Questions