trying to play HLS stream with NAudio

0

It looks like my initial trouble is with find(making) a reader. I'm a bit new to working with streams but I tried to send it to the StreamMediaFoundationReader which I understand is more of a catch all.

        private void playButton_Click(object sender, EventArgs e)
    {

        new Thread(delegate (object o) {
            var response =
                WebRequest.Create("http://ccbd-hls-pri.learfieldccbd.com/25/smil:test_adapt.smil/playlist.m3u8")
                    .GetResponse();
            using (var stream = response.GetResponseStream())
            {
                byte[] buffer = new byte[65536];
                int read;
                while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    var pos = ms.Position;
                    ms.Position = ms.Length;
                    ms.Write(buffer, 0, read);
                    ms.Position = pos;
                }
            }
        }).Start();

        while (ms.Length < 64)
        {
            Thread.Sleep(1000);
        }

        ms.Position = 0;

        using (
            WaveStream blockAlignedStream =
                new BlockAlignReductionStream(WaveFormatConversionStream.CreatePcmStream((new StreamMediaFoundationReader(ms)))))
        {
            using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
            {
                waveOut.Init(blockAlignedStream);
                waveOut.Play();
                while (waveOut.PlaybackState == PlaybackState.Playing)
                {
                    System.Threading.Thread.Sleep(100);
                }
            }
        }
    }

When I try to play this, I get a System.Runtime.InteropServices.COMException {"The byte stream type of the given URL is unsupported. (Exception from HRESULT: 0xC00D36C4)"}

anyone know of a way to get NAudio to read the stream listed in this example?

c#
naudio
hls
asked on Stack Overflow Sep 7, 2017 by Aaron Rumford

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0