title: audio duration in Safari always returning infinity when streaming through PHP
body: <p>For some reason in Safari (and no other major browser), when I serve an MP3 via <strong>PHP</strong> through an <code>Audio</code> context in <strong>JavaScript</strong>, the duration of the MP3 is always returned as <code>infinity</code>.</p>
  <p>This problem has stumped me for the last few days and after reading a few links (including <a href="https://stackoverflow.com/questions/9629223/audio-duration-returns-infinity-on-safari-when-mp3-is-served-from-php">this</a> one) in search for a solution, I have not progressed at all.</p>
  <hr>
  <h1>My code</h1>
  <h3>PHP:</h3>
  <pre><code>$path = &quot;path/to/file.mp3&quot;;
  $file = [
      &quot;path&quot;      =&gt; $path,
      &quot;size&quot;      =&gt; filesize($path),
      &quot;bitrate&quot;   =&gt; $bitrate
  ];
  
  header(&quot;Accept-Ranges: bytes&quot;, false);
  header(&quot;Content-Length: &quot; . $file[&quot;size&quot;], false);
  header(&quot;Content-Type: audio/mpeg&quot;, false);
  
  echo file_get_contents($file[&quot;path&quot;]);
  
  exit;
  </code></pre>
  <h3>JavaScript:</h3>
  <pre><code>var audio = new Audio(url);
  // returns infinite on Safari
  // returns 312.27311 on Chrome and Firefox (which is correct)
  console.log(audio.duration);
  </code></pre>
  <hr>
  <p>I'm still yet to figure out why this problem is only in Safari and what is causing it in the first place, so if anyone has a solution it would be much appreciated!</p>
  <p>Cheers.</p>