This project has moved and is read-only. For the latest updates, please go here.

M3U8Parser object

Jan 5, 2015 at 1:50 PM
Hi and happy new year !

I try the last version of the package (phonesm-1.4.3 alpha) and some changes has been made to the M3U8Parser object.

With the 1.2.2 version i can parse a m3u8 file very simply with the function parseAsync().
But now i don't know how to use. The RetryManager parameter is very obscure to me.

Someone can make a simple example to how to use it ? This would be very useful.

Thank you in advance for your answers. =)
Coordinator
Jan 6, 2015 at 1:15 AM
You can either use one of the other extension methods (like "Parse(this M3U8Parser parser, Uri baseUrl, Stream stream, Encoding encoding = null)") or supply an instance of RetryManager. If you are using the DI stuff, then Autofac should know how to provide one; if not, you should be able to do this: "new RetryManager(new PlatformServices())" (platform services is used to randomize the delay between retries). The RetryManager is thread safe, so it can be reused.

The actual implementation of ParseAsync() does an async read into a memory buffer, then feeds that to GetExtendedLines() (through the "Parse()" extension method I mentioned above):
        public static Task<Uri> ParseAsync(this M3U8Parser parser, IWebReader webReader, IRetryManager retryManager, Uri playlist, CancellationToken cancellationToken)
        {
            var retry = retryManager.CreateWebRetry(2, 250);

            return retry.CallAsync(() =>
                webReader.ReadStreamAsync(playlist, retry, (actualPlaylist, stream) =>
                {
                    parser.Parse(actualPlaylist, stream);

                    return actualPlaylist;
                }, cancellationToken),
                cancellationToken);
        }
The retryManager is used to make sure that transient problems do not stop playback (and is extremely unlikely to help if you are dealing with a local file).

Note that the change was made as part of getting rid of the global (i.e., public and static) IPlatformServices.

And you're welcome (and welcome to 2015).
Jan 6, 2015 at 6:00 PM
Many thanks for your explanations ! All works like a charm. =)