auto detect playlist type VS forcing known type

Jan 22, 2015 at 3:59 PM
Hi,
Sometimes the code cannot identify what kind of playlist it is receiving.
example: http://kjram.akacast.akamaistream.net/7/89/20135/v1/auth.akacast.akamaistream.net/kjr-am.m3u

How could I force it?

Here's my debug output


HttpConnectionWebReaderManager.DetectContentTypeAsync() url ext "http://kjram.akacast.akamaistream.net/7/89/20135/v1/auth.akacast.akamaistream.net/kjr-am.m3u" type M3U (audio/mpegURL)
'Windows.Media.BackgroundPlayback.exe' (CoreCLR: .): Loaded 'C:\windows\system32\System.Net.Primitives.ni.DLL'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Windows.Media.BackgroundPlayback.exe' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.XML.XDOCUMENT.NI.DLL'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Windows.Media.BackgroundPlayback.exe' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.XML.LINQ.NI.DLL'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Windows.Media.BackgroundPlayback.exe' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.XML.NI.DLL'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll
Unable to get us-ascii encoding
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll
Unable to get Windows-1252 encoding
'Windows.Media.BackgroundPlayback.exe' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.GLOBALIZATION.NI.DLL'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Opening
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll
PlaylistSegmentManagerFactory.SetMediaSource(): program not found
A first chance exception of type 'System.IO.FileNotFoundException' occurred in SM.Media.DLL
PlaylistSegmentManagerFactory.SetMediaSource(): unable to load playlist: Unable to load program
A first chance exception of type 'System.IO.FileNotFoundException' occurred in SM.Media.DLL
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll
TsMediaManager.OpenMediaAsync failed: Unable to load program
TsMediaManager.SetMediaState() Opening -> Error
TsMediaManager.ReportState() state Error message Unable to play media
MediaStreamFacadeBase.MediaManagerOnStateChange() to Error: Unable to play media
Media manager state in background agent: Error, message: Unable to play media
TsMediaManager.CleanupFaileOpenAsync() state Error
WinRtMediaStreamConfigurator.ReportError(): Unable to play media
A first chance exception of type 'System.AggregateException' occurred in SM.Media.DLL
Error
A first chance exception of type 'System.AggregateException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.AggregateException' occurred in mscorlib.ni.dll
MediaStreamFacadeBase.CreateAsync() failed: System.AggregateException: Unable to load program
System.IO.FileNotFoundException: Unable to load program
System.IO.FileNotFoundException: Unable to load program

MediaStreamFacadeBase.CloseAsync()
MediaStreamFacadeBase.CloseMediaAsync()
MediaStreamFacadeBase.UnlockedCloseMediaAsync()
MediaStreamFacadeBase.CloseMediaAsync() calling mediaManager.CloseAsync()
TsMediaManager.CloseMediaAsync()
TsMediaManager.CloseAsync()
TsMediaManager.SetMediaState() Error -> Closing
TsMediaManager.ReportState() state Closing message
MediaStreamFacadeBase.MediaManagerOnStateChange() to Closing:
Media manager state in background agent: Closing, message:
TsMediaManager.CloseCleanupAsync()
WinRtMediaStreamConfigurator.CloseAsync()
Closing
TsMediaManager.DisposeReaders()
TsMediaManager.SetMediaState() Closing -> Closed
TsMediaManager.ReportState() state Closed message
Closing
MediaStreamFacadeBase.MediaManagerOnStateChange() to Closed:
MediaStreamFacadeBase.StopMediaAsync()
A first chance exception of type 'System.OperationCanceledException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.OperationCanceledException' occurred in mscorlib.ni.dll
Media manager state in background agent: Closed, message:
TsMediaManager.CloseAsync() completed
MediaStreamFacadeBase.CloseMediaAsync() returned from mediaManager.CloseAsync()
MediaStreamFacadeBase.CleanupMediaManager()
TsMediaManager.Dispose()
TsMediaManager.CloseAsync()
TsMediaManager.SetMediaState() Closed -> Closing
TsMediaManager.CloseCleanupAsync()
WinRtMediaStreamConfigurator.CloseAsync()
Closed
TsMediaManager.DisposeReaders()
TsMediaManager.SetMediaState() Closing -> Closed
TsMediaManager.ReportState() state Closing message
TsMediaManager.ReportState() state Closed message
TsMediaManager.CloseAsync() completed
TsMediaManager.Dispose()
WinRtMediaStreamConfigurator.Dispose()
ValidateEvent Invalid state transition: state Idle event DisposeCalled
MediaStreamFacadeBase.CleanupMediaManager() completed
MediaStreamFacadeBase.CloseMediaAsync() completed
A first chance exception of type 'System.AggregateException' occurred in SM.Media.DLL
A first chance exception of type 'System.AggregateException' occurred in mscorlib.ni.dll
Error Extra
Coordinator
Jan 22, 2015 at 4:57 PM
Edited Jan 22, 2015 at 4:59 PM
Hmmmm.... It's actually a bit more interesting than that.

M3U8Parser's Parse() insists that "#EXTM3U" should be the first line in the file, so it fails to see any of the URLs in the M3U. While it is reasonable for it to look for the #EXTM3U, aborting if it can't see it is probably taking things a bit far. I'll take a further look at this, but in the meantime, you could either hard code the URL from the M3U that you want to use or you could fetch and parse the M3U by hand. Once you have the stream URL you want to play, you should be able to use it instead of the M3U url Something like this should return the list if given that M3U url (assuming this is for WP8.1/WinRT):
using SM.Media.Utility.TextEncodings;
   ...
    static async Task<List<Uri>> Read1252UrlsAsync(Uri url)
    {
        var urls = new List<Uri>();

        using (var client = new Windows.Web.Http.HttpClient())
        {
            using (var stream = await client.GetInputStreamAsync(url).AsTask().ConfigureAwait(false))
            using (var reader = new StreamReader(stream.AsStreamForRead(), new Windows1252Encoding()))
            {
                for (;;)
                {
                    var line = await reader.ReadLineAsync().ConfigureAwait(false);

                    if (null == line)
                        return urls;

                    Uri lineUrl;

                    if (Uri.TryCreate(url, line, out lineUrl))
                        urls.Add(lineUrl);
                }
            }
        }
    }
I didn't actually test this.
Coordinator
Jan 22, 2015 at 4:58 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jan 23, 2015 at 6:21 AM
As a quicker fix I just commented
  //if (line != "#EXTM3U")
                    //{
                    //    var d = lines as IDisposable;

                    //    if (null != d)
                    //        d.Dispose();

                    //    return;
                    //}
And all works now.

One problem was solved while the question still exists ...
This stream: ​http://sc3c-sjc.1.fm:7044/?type=.flv is AAC as far as I know but it's not recognized.. I just like to force it :D
Coordinator
Jan 23, 2015 at 8:50 AM
Edited Jan 23, 2015 at 8:50 AM
That should do it.

To skip the top level detection logic, you can set IMediaStreamFacade's ContentType to something other than null:
    _mediaStreamFacade.ContentType = ContentTypes.Aac;
That should work for an ADTS AAC stream. If you have a PLS or M3U/M3U8 playlist that points to another stream that is then not detected as AAC, you could override the default IContentTypeDetector implementation.

The "?type=.flv" in the above URL will likely return a Flash Video stream (possibly with containing AAC packets). It is more likely to work if one leaves off the "?type=.flv' query string. I didn't try playing it, but "curl" gives the following:
~>curl -v 'http://sc3c-sjc.1.fm:7044/' | hexdump -C | head -100
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 205.164.62.22...
* Connected to sc3c-sjc.1.fm (205.164.62.22) port 7044 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.40.0
> Host: sc3c-sjc.1.fm:7044
> Accept: */*
>
{ [12 bytes data]
00000000  49 43 59 20 32 30 30 20  4f 4b 0d 0a 69 63 79 2d  |ICY 200 OK..icy-|
00000010  6e 6f 74 69 63 65 31 3a  3c 42 52 3e 54 68 69 73  |notice1:<BR>This|
00000020  20 73 74 72 65 61 6d 20  72 65 71 75 69 72 65 73  | stream requires|
00000030  20 3c 61 20 68 72 65 66  3d 22 68 74 74 70 3a 2f  | <a href="http:/|
00000040  2f 77 77 77 2e 77 69 6e  61 6d 70 2e 63 6f 6d 2f  |/www.winamp.com/|
00000050  22 3e 57 69 6e 61 6d 70  3c 2f 61 3e 3c 42 52 3e  |">Winamp</a><BR>|
00000060  0d 0a 69 63 79 2d 6e 6f  74 69 63 65 32 3a 53 48  |..icy-notice2:SH|
00000070  4f 55 54 63 61 73 74 20  44 69 73 74 72 69 62 75  |OUTcast Distribu|
00000080  74 65 64 20 4e 65 74 77  6f 72 6b 20 41 75 64 69  |ted Network Audi|
00000090  6f 20 53 65 72 76 65 72  2f 4c 69 6e 75 78 20 76  |o Server/Linux v|
000000a0  31 2e 39 2e 38 3c 42 52  3e 0d 0a 69 63 79 2d 6e  |1.9.8<BR>..icy-n|
000000b0  61 6d 65 3a 31 2e 46 4d  20 2d 20 42 4f 4d 42 41  |ame:1.FM - BOMBA|
000000c0  59 20 42 45 41 54 53 20  49 4e 44 49 41 20 52 41  |Y BEATS INDIA RA|
000000d0  44 49 4f 0d 0a 69 63 79  2d 67 65 6e 72 65 3a 77  |DIO..icy-genre:w|
000000e0  6f 72 6c 64 0d 0a 69 63  79 2d 75 72 6c 3a 68 74  |orld..icy-url:ht|
000000f0  74 70 3a 2f 2f 77 77 77  2e 31 2e 46 4d 0d 0a 63  |tp://www.1.FM..c|
00000100  6f 6e 74 65 6e 74 2d 74  79 70 65 3a 61 75 64 69  |ontent-type:audi|
00000110  6f 2f 61 61 63 70 0d 0a  69 63 79 2d 70 75 62 3a  |o/aacp..icy-pub:|
00000120  31 0d 0a 69 63 79 2d 62  72 3a 36 34 0d 0a 0d 0a  |1..icy-br:64....|
00000130  ff f9 5c 80 2e 62 44 21  1b 55 35 a1 95 07 63 a1  |..\..bD!.U5...c.|
00000140  18 28 46 22 52 ca a8 8a  95 05 44 44 13 11 12 54  |.(F"R.....DD...T|
The content type returned is "audio/aacp" and the actual stream data looks like ADTS AAC ("ff f9 ...").

Trying the same thing with the "?type=.flv" query string results in a content type of "video/x-flv" and what looks like FLVish data.
Coordinator
Jan 27, 2015 at 12:10 AM
b666a20e3660 should let things work without "#EXTM3U" at the top of the file.