I want to make a program which will display currently playing songs from an internet radio stream(SomaFM). I am using HTTPoison library in Elixir. But I am failing to get a response. It just hangs.
I am using the following code:
HTTPoison.start
url = "http://ice1.somafm.com/lush-128-mp3"
headers = [{"Icy-Metadata", "1"}]
with {:ok, %HTTPoison.Response{body: body}} <- HTTPoison.get(url, headers) do
body |> Poison.decode! |> IO.inspect
else
{:error, %HTTPoison.Error{reason: reason}} ->
IO.inspect reason
end
end
I am actually very new to elixir, so if anyone can help me I would be really grateful.
When you use the
get
request you are requesting the audio file. If it's streaming then I guess it would never stop "downloading". You will need to do it differently.I actually wrote up a quick example library. You could copy this module code, since you already have
HTTPoison
, you should havehackney
as a dependency already.Example module: https://github.com/ryanwinchester/shoutcast_ex/blob/master/lib/shoutcast.ex
I added the
Meta
struct to save some of the data I find interesting, you could easily remove that and modify the function it to just return the title, if you were only interested in that.