Stream audio file

Hi,
This following code streams a file to a process I want to stream audio/mp3 to many users who will hear via html5 audio tag how can it be done via File.stream! ?

defmodule Test do
  def say do
    receive do
      {from, msg} ->
        IO.puts "Process #{inspect self} says: #{msg}"
        fpath = "./test.txt"
        stream_bytes = 128
        File.stream!(fpath, [], stream_bytes)
        |> Enum.each(fn chunk ->
            IO.puts "* streaming #{stream_bytes} bytes...\n #{chunk}"
        end)
        say
    end
  end
end
# p = spawn(Test, :say, []);send p, {self, "a message"}
3 Likes

This blog post goes through creating a media streaming application.

http://elixirdose.com/post/building-a-simple-stream-media-app

3 Likes

I’m sorry, this blog post is not helpful because it doesn’t create stream
it just creates html5 audio tag

I want end users will join together to server.com/room
the page will contain this html

<\audio controls><\source src=“/service/stream” type=“audio/mp3”></audio>

and ‘server.com/service/stream’ will stream mp3 file that I will choose
and all connected users will listen to the stream
a.k.a. radio server
and I want to benchmark how many users can my server handle (without a delay)

3 Likes

here is an erlang example to stream mp3 file
can anyway translate to Elixir ?

2 Likes