Dynamically Stream Audio Files to Icecast via HTTP Request in Liquidsoap #4403
Unanswered
acrylo-code
asked this question in
Q&A
Replies: 1 comment 4 replies
-
Hi @acrylo-code, stream = blank()
effects_queue = request.queue()
radio = add([stream, effects_queue])
# Stream to Icecast
output.icecast(%mp3, stream, host=server, port=port, password=password, mount=mount)
# HTTP handler to play sound effects dynamically based on the file parameter
def handler(request, response) =
file_name = request.query["file"] # Extract the file query parameter
if file_name == "" then
response.html("<p>No file specified. Please provide a valid file parameter.</p>")
else
base_path = "/audio"
file_name = path.concat(base_path, file_name)
if not file.exists(file_name) then
response.html("<p>Doesn't exist.</p>")
elsif not file.is_directory(file_name)
response.html("<p>Not a file.</p>")
else
effects_queue.push.uri("file_name")
response.html("<p>Playing: #{file_name}</p>")
end
end
end
# Register HTTP endpoint with GET method and correct path
harbor.http.register(port=6001, method="GET", "/effect", handler) |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Question:
I’m trying to dynamically stream audio effects (or files) using Liquidsoap and Icecast, based on an HTTP request. I want to be able to send a request like http://:6001/effect?file=effect1.mp3 and have the corresponding audio file played in the stream. Here’s the Liquidsoap code I’m working with, but it seems like the request handling and streaming aren't working as expected.
Could someone help me identify what’s wrong and suggest how to properly stream the requested files to Icecast? I'm very new to LiquidSoap and don't know the language good enough to continue.
Code I have so far:
What I Want to Achieve:
I want to dynamically stream audio files (e.g., sound effects) to the Icecast stream based on an HTTP request.
For example, if I access the following URL: http://:6001/effect?file=effect1.mp3, I want effect1.mp3 to be played in the Icecast stream that’s available at http://:8000/stream.mp3.
I want the stream to update automatically and play the requested file.
The requested files should be able to play simultaneously
What’s Happening:
When I make a request (e.g., http://:6001/effect?file=effect1.mp3), the server responds with the message "Playing: effect1.mp3".
However, the requested audio file doesn’t actually play in the stream, and no update seems to occur in the Icecast output.
What I’ve Tried:
I’ve ensured the audio files exist in the /audio/ folder.
I’m using a simple single() function to load the audio file dynamically and attempting to add it to the stream.
What I Need Help With:
I believe I may be missing something with the way I'm dynamically adding the requested file to the stream, or with the HTTP request handling logic.
Could someone point out any issues or provide guidance on how to properly stream the requested file to Icecast?
Thanks in advance for any help!
Beta Was this translation helpful? Give feedback.
All reactions