I am working on an mp3 streaming web application. I am using an external API to get the mp3 url, the problem is that all mp3's are bounded to the IP requesting the file (in this case my server) and it can be streamed/downloaded only by the server, any other IP will result in a 404.
What I am looking for is the best option for my server to act as a relay/proxy between the mp3 and the user wanting to listen to it.
This is somehow a problem for my bandwidth, but I see no alternative.
This is the code I am using, but as it broadcasts at the same time it downloads, the web app can't get the mp3 tags and it somehow broke the web app player.
if (isset($_GET['name']) AND isset($_GET['url'])){
$url = urldecode($_GET['url']);
if ((strpos($url,'xxxxxx') !== false) || (strpos($url,'xxxxxx') !== false)) {
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $_GET['name'] . ' - xxxxxx.mp3"');
readfile(urldecode($_GET['url']));
}
else {
header("HTTP/1.0 404 Not Found");
}
}
else {
header("HTTP/1.0 404 Not Found");
}
You need to use an audio stream wrapper. An example would be OGG. It's set up basically the same way a message socket server is set up. So if you have never made a message socket server, I would recommend watching a youtube video on how to set up a message server with sockets first.
Sorry your question isn't a straight answer question. Not without first knowing what you know about streaming data.
http://php.net/manual/en/wrappers.audio.php
https://www.youtube.com/watch?v=XkBaba5q6dc&list=PLgiqzl4BEJTOiJolWtRF2tEhlkX1r-s5a