static async Task PlayAsync(SingleStreamSimulator simulator, CancellationToken cancellationToken) { var source = new Uri(Sources[0]); if (source.HasExtension(".pls")) { using (var client = new HttpClient()) using (var response = await client.GetAsync(source, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false)) { response.EnsureSuccessStatusCode(); using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false)) using (var reader = new StreamReader(stream)) { var pls = new PlsParser(response.RequestMessage.RequestUri); if (!await pls.ParseAsync(reader).ConfigureAwait(false)) throw new FileNotFoundException("Unable to parse PLS playlist"); var track = pls.Tracks.FirstOrDefault(); if (null == track) throw new FileNotFoundException("Empty PLS playlist"); Uri trackUrl; if (!Uri.TryCreate(pls.BaseUrl, track.File, out trackUrl)) throw new FileNotFoundException("Invalid URL in PLS playlist"); source = trackUrl; } } } await simulator.StartAsync(source, cancellationToken).ConfigureAwait(false); }