I need to broadcast audio content to the network, receive it and play in the browser “on the fly”. The audio content is just list of mp3 files. and on client side it should looks like endless audio stream without state. Something like YouTube live streams. Or smth like online radio. But I really don’t know anything about that. Can anyone helps me with that? How it works, which protocol is used for sending and receiving data? Anything that can help me with that. At the best I’m looking for a solution for .NET, but I will be glad for anything that can help, at least to understand how it works in general. Thank you.
1 Answers
One way to do it would be with help of ffmpeg.
You can use ffmpeg to create DASH or HLS playlist https://ffmpeg.org/ffmpeg-formats.html#hls-2
FFMPEG supports other streaming solutions too.
To invoke ffmpeg you have to find binaries that are compatible with your system that your server is running on (windows, linux). Here is how can you start external process from C#: How do I start a process from C#?
To play your playlist in browser you can use VideoJS. It has built-in support for DASH and HLS: https://videojs.com/ (it can play audio too)
Build your logic to manage / update playlists and then you just need to create HTTP service that can serve your playlist file. VideoJS will play it for you.
If you go with HLS then you probably should read this: https://developer.apple.com/streaming/
If you go with DASH then read this: https://mpeg.chiariglione.org/standards/mpeg-dash
Another way is to use out of the box solutions which often aren't free:
-
-
But in case I want to pause streaming any audio and then in future of course resume it from where I stopped. So what I need to do with my m3u8 playlist file to “pause” streaming?and then for resume? – user3233682 Dec 08 '18 at 23:27
-
And on the client side, it should looks like the stream is going on, but nothing playing. So can it be done with HLS? – user3233682 Dec 08 '18 at 23:30
-
Also, am I right, on the client side I need to periodically manually download and update my playlist via js, if there are any changes? This is for what I need VideoJs, yep? Or this will be done by browser/os with a magic? – user3233682 Dec 09 '18 at 14:54
-
Yes VideoJS will perodically check if your playlist has changed. You can configure videojs and your playlist updates so it will look like continuous stream. "Pause" could be implemented in many ways, on your streaming server or client/browser or some combination of both possibly using SignalR as communication channel between browser and your server. Some browsers may not allow you to use autoplay feature without user interaction: https://stackoverflow.com/a/49391211/6440521 Not sure if this apply to audio though – Dec 10 '18 at 12:58