K
K
Kevin Mitnick2016-04-10 15:27:35
PHP
Kevin Mitnick, 2016-04-10 15:27:35

PHP how to play audio from another server?

Suppose I have a link with an output audio file (I took a link from VK as an example), I access my link from my site using the "audio" tag, which broadcasts the audio file to the player (the file code itself, to which I address, written below). A very important factor is that audio files are about 1 hour long and their weight is more than 100mb (there are no problems with files of 4 minutes). Everything works, the audio is played, but:
1. Only part of the file is downloaded from my link, and after the player approaches this part, the playback is interrupted.
2. If you try to rewind the file for more than a minute, the file will stop playing.
As soon as I did not try to torment the headlines, nothing happened. at the moment there are such headers that track the headers of the request itself and take a range of bytes from it. Actually the question is how to make the audio play with rewind and load not only part of the file, but the entire file.
The code itself:

$file= "https://cs1-48v4.vk-cdn.net/p13/82193c0223859a.mp3?extra=PFQ6YTvJZQsoC4vavjB1rpIS83wlUNo63rvOR5_f9fvNWHsQ6nhuQx8U463GZGQR1TTN6eB7bi_uRxhHbhm1LgjWcUMG99YZlkGFHZyHq16UG_cjDH00RKRPgzQJJbJy4ZizVGiN1cLa";
  $len = get_headers($file,1);
  $heads = getallheaders();

  header("Content-Length:".$len['Content-Length']);
  header("Content-Length:".($len['Content-Length'] - str_replace(array("-","=","bytes"," "), "", $heads["Range"])));
  header("Accept-Ranges:bytes");
  header("Cache-Control:max-age=1468800");
  header("Content-Type:audio/mpeg");
  isset($heads["Range"]) ? (header("Content-Range:" . str_replace("=", " ", $heads["Range"]).($len['Content-Length']-1)."/".$len['Content-Length'])) : header("Content-Range:bytes 0-" . $len['Content-Length']);

  readfile($file);

PS: I know that the link is issued by ip in VK, I received the link to the server itself.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DuD, 2016-04-10
@DuD

Try increasing the timeout.

D
Denis_Ustinow, 2018-11-23
@Denis_Ustinow

Issue not resolved?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question